Hooded Plover Demography

Nest and Chick Survival Modelling

Authors
Affiliations

Department of Ornithology, Max Planck Institute for Biological Intelligence, Germany

Jasmin Rooks

Coastal and Wetland Birds Program, BirdLife Australia

Lucinda Plowman

Coastal and Wetland Birds Program, BirdLife Australia

Grainne Maguire

Coastal and Wetland Birds Program, BirdLife Australia

Mike Weston

Life and Environmental Sciences, Deakin University, Australia

Published

August 22, 2025

Code
knitr::opts_chunk$set(cache = TRUE)

Prerequisites

R packages

  • The following packages are needed for analysis and can be easily installed from CRAN or GitHub by running the following code chunk:
Code
# a vector of all the packages needed in the project
packages_required_in_project <- c("tidyverse",
                                  "readxl",
                                  "RMark",
                                  "RColorBrewer",
                                  "patchwork",
                                  "mapview",
                                  "lubridate",
                                  "extrafont",
                                  "here",
                                  "DT",
                                  "leaflet",
                                  "sf",
                                  "leafpop",
                                  "tsibble",
                                  "corrplot",
                                  "gghalves",
                                  "gam",
                                  "pscl",
                                  "gamlss",
                                  "gt",
                                  "lme4",
                                  "timeDate",
                                  "circular",
                                  "openxlsx", 
                                  "fuzzyjoin")
                                  
# of the required packages, check if some need to be installed
new.packages <- 
  packages_required_in_project[!(packages_required_in_project %in% 
                                   installed.packages()[,"Package"])]

# install all packages that are not locally available
if(length(new.packages)) install.packages(new.packages)

# load all the packages into the current R session
lapply(packages_required_in_project, require, character.only = TRUE)

# set the home directory to where the project is locally based (i.e., to find 
# the relevant datasets to import, etc.
here::set_here()

Plotting themes

  • The following plotting themes, colors, and typefaces are used throughout the project:
Code
# Find fonts from computer that you want. Use regular expressions to do this
# For example, load all fonts that are 'verdana' or 'Verdana'
extrafont::font_import(pattern = "[V/v]erdana", prompt = FALSE) 

# check which fonts were loaded
extrafont::fonts()
extrafont::fonttable()
extrafont::loadfonts() # load these into R

# define the plotting theme to be used in subsequent ggplots
luke_theme <- 
  theme_bw() +
  theme(
    text = element_text(family = "Verdana"),
    legend.title = element_text(size = 10),
    legend.text = element_text(size = 8),
    axis.title.x = element_text(size = 10),
    axis.text.x  = element_text(size = 8), 
    axis.title.y = element_text(size = 10),
    axis.text.y = element_text(size = 8),
    strip.text = element_text(size = 10),
    panel.grid.major = element_blank(),
    panel.grid.minor = element_blank(),
    axis.ticks = element_line(size = 0.5, colour = "grey40"),
    axis.ticks.length = unit(0.2, "cm"),
    panel.border = element_rect(linetype = "solid", colour = "grey"),
    legend.position = c(0.1, 0.9)
  )

region_names <- c(
  'FP' = "Fleurieu Peninsula",
  'MP' = "Mornington Peninsula",
  'BSC' = "Bellarine / Surf Coast")

# set mapview to show satellite imagery
mapviewOptions(basemaps = c("Esri.WorldImagery"))

Project-specific Functions

The following custom functions are used to

%!in%

This function simply does the opposite of %in%, which is used to test if elements on the left-hand side are members of the set defined by the right-hand side. %!in% returns a logical vector indicating whether each element on the left-hand side is not present in the right-hand side.

Code
`%!in%` = Negate(`%in%`)

nest_import()

This function imports the HOPL nest survival data stored as Excel sheets into R, wrangles it into a single dataframe, and prepares it for subsequent analysis (e.g., specifies relevent date columns, etc.)

arguments:

  • year_1: first calender year of the focal data sheet (e.g., 2002)
  • year_2: second calender year of the focal data set (i.e., always year_1 + 1)
  • file_name: name of the Excel sheet to import data from
  • site: site that the data describes (MP, FP, or BSC)
  • extra_text: the extra text associated with each sheet in the Excel file (i.e., besides from the year)
  • first_found_date_col: the number of the column in the sheets that correspond to the first found date
  • last_alive_date_col: the number of the column in the sheets that correspond to the last alive date
  • last_checked_col: the number of the column in the sheets that correspond to the last checked date
Code
nest_import <-
  function(year_1, year_2, file_name, site, extra_text = NULL, 
           first_found_date_col, last_alive_date_col, last_checked_col) {
    if(is.null(extra_text)){
      file <- 
        read_excel(paste0("data/", file_name), 
                   sheet = paste0(site, " ", year_1, "_", str_sub(year_2, 3, 4)), 
                   col_types = "text", na = "n/a")
    }
    else{
      file <- 
        read_excel(paste0("data/", file_name), 
                   sheet = paste0(site, " ", year_1, "_", str_sub(year_2, 3, 4), extra_text), 
                   col_types = "text", na = "n/a")
    }
    file %>%
      # simplify column names
      rename(first_found = first_found_date_col,
             last_alive = last_alive_date_col,
             last_checked = last_checked_col,
             Fate = `Hatch?`,
             season = Season,
             # site = Site,
             site = `Suggested update to site name`,
             nest_ID = `Nest ID`,
             nest_hab = `Nest habitat`,
             management_status = `Nest managed?`,
             management_type = `Management type`,
             nest_lat = `Nest latitude`,
             nest_lon = `Nest longitude`,
             chick_1st_ob = which(names(file) %in% c("Date chicks sighted", "Chicks first obsv date"))[1],
             clutch_comp = which(names(file) %in% c("Known clutch complete date", "Known laying date")),
             state_1st_ob = `Age stage first observed`) %>% 
      
      # consolidate columns
      dplyr::select(season, site, nest_ID, first_found, last_alive, last_checked, Fate, nest_hab, 
                    management_status, management_type, nest_lat, nest_lon,
                    chick_1st_ob, clutch_comp, state_1st_ob) %>% 
      
      # wrangle: clean up Fate column for consistency
      mutate(Fate = ifelse(Fate == "?", "Unk", Fate)) %>% 
      mutate(Fate = toupper(Fate)) %>%
      # remove rows that have either an NA or numbers in the first_found column
      filter(is.na(first_found) | grepl("^\\s*-?\\d+(\\.\\d+)?\\s*$", first_found)) %>%
      # clean up the last_checked and last_alive columns so that non-number data are dropped to NA
      mutate(last_checked = ifelse(!is.na(last_checked) & 
                                     !grepl("^\\s*-?\\d+(\\.\\d+)?\\s*$", last_checked), 
                                   NA, last_checked)) %>% 
      mutate(last_alive = ifelse(!is.na(last_alive) & 
                                   !grepl("^\\s*-?\\d+(\\.\\d+)?\\s*$", last_alive), 
                                 NA, last_alive))%>% 
      # wrangle: if date last alive is "Unk." make it "NA"
      mutate(last_alive = ifelse(str_detect(last_alive, "Unk."), NA, last_alive),
             # change Fate to 1 or 0 (1 = failed, 0 = hatched, NA = unknown)
             Fate = ifelse(Fate == "Y", 0, 
                           ifelse(Fate == "N", 1, 
                                  ifelse(Fate == "UNK", NA, "XXX")))) %>%
      # remove nests without Fate information
      filter(Fate %in% c("0", "1")) %>% 
      # classify the chick_1st_ob and clutch_comp columns as.Date()
      mutate(chick_1st_ob = case_when(
          # Excel serial dates stored as numbers
          str_detect(chick_1st_ob, "^[0-9]+$") ~ as.Date(as.numeric(chick_1st_ob), origin = "1899-12-30"),
          
          # Dates with extra text in parentheses — extract only the date part
          str_detect(chick_1st_ob, "^\\d{1,2}/\\d{1,2}/\\d{2,4}") ~ suppressWarnings(
            dmy(str_extract(chick_1st_ob, "^\\d{1,2}/\\d{1,2}/\\d{2,4}"))
          ),
          
          # Everything else (including "Unk", "Failed during laying") → NA
          TRUE ~ as.Date(NA)
        ), 
             clutch_comp =  case_when(
          # Excel serial dates stored as numbers
          str_detect(clutch_comp, "^[0-9]+$") ~ as.Date(as.numeric(clutch_comp), origin = "1899-12-30"),
          
          # Dates with extra text in parentheses — extract only the date part
          str_detect(clutch_comp, "^\\d{1,2}/\\d{1,2}/\\d{2,4}") ~ suppressWarnings(
            dmy(str_extract(clutch_comp, "^\\d{1,2}/\\d{1,2}/\\d{2,4}"))
          ),
          
          # Everything else (including "Unk", "Failed during laying") → NA
          TRUE ~ as.Date(NA)
        )) %>%
      # if the clutch completion date is NA, then estimate it as 35 days before estimated hatch date
      # using the date of first chick observation and the size of the chicks when seen
      mutate(clutch_comp = ifelse(Fate == 0 & is.na(clutch_comp) & !is.na(chick_1st_ob) & !is.na(state_1st_ob),
                                        ifelse(state_1st_ob == "1/3 adult size, fluffy", chick_1st_ob - 3 - 35,
                                               ifelse(state_1st_ob == "1/2 adult size, fluffy", chick_1st_ob - 10 - 35,
                                                      ifelse(state_1st_ob == "2/3 adult size, fluffy", chick_1st_ob - 19 - 35,
                                                             ifelse(state_1st_ob == "Adult size, mottled grey", chick_1st_ob - 30 - 35,
                                                                    ifelse(state_1st_ob == "Fledged", chick_1st_ob - 35 - 35,
                                                                           ifelse(state_1st_ob == "wet in nest", chick_1st_ob - 35, NA)))))), 
                                        ifelse(Fate == 0 & is.na(clutch_comp) & !is.na(chick_1st_ob) & is.na(state_1st_ob), NA, NA)) %>% as.Date()) %>%
      # specify the last_alive2 date for hatched nests as the estimated hatch date
      # using the date of first chick observation and the size of the chicks when seen
      mutate(last_alive2 = ifelse(Fate == 0 & !is.na(clutch_comp) & is.na(last_alive), clutch_comp + 35,
                                 ifelse(Fate == 0 & is.na(clutch_comp) & !is.na(chick_1st_ob) & !is.na(state_1st_ob) & is.na(last_alive),
                                        ifelse(state_1st_ob == "1/3 adult size, fluffy", chick_1st_ob - 3,
                                               ifelse(state_1st_ob == "1/2 adult size, fluffy", chick_1st_ob - 10,
                                                      ifelse(state_1st_ob == "2/3 adult size, fluffy", chick_1st_ob - 19,
                                                             ifelse(state_1st_ob == "Adult size, mottled grey", chick_1st_ob - 30,
                                                                    ifelse(state_1st_ob == "Fledged", chick_1st_ob - 35,
                                                                           ifelse(state_1st_ob == "wet in nest", chick_1st_ob, NA)))))), 
                                        ifelse(Fate == 0 & is.na(clutch_comp) & !is.na(chick_1st_ob) & is.na(state_1st_ob) & is.na(last_alive), NA, NA))) %>% as.Date()) %>% 
      # clean up the last_alive date given the new last_alive2 date extracted above
      mutate(last_alive = ifelse(!is.na(last_alive2), 
                                paste0(str_sub(as.character(last_alive2), 9, 10),
                                       str_sub(as.character(last_alive2), 6, 7),
                                       str_sub(as.character(last_alive2), 1, 4)), last_alive)) %>% 
      mutate(
        # wrangle: if last_alive has a date and last_checked is NA, then change 
        # last_checked to the date in last_alive
        last_checked = ifelse(!is.na(last_alive) & is.na(last_checked),
                              last_alive,
                              # if both last_alive and last_checked is "NA", then
                              # change last_checked to the first_found date
                              ifelse(is.na(last_alive) & is.na(last_checked),
                                     first_found,
                                     last_checked))) %>%
      mutate(
        # wrangle: if last_alive is NA and the nest hatched and last_checked has a
        # date, then specify last_alive as the date from last_checked
        last_alive = ifelse(is.na(last_alive) & Fate == "0" & !is.na(last_checked),
                            last_checked,
                            # if the last_alive is NA and the nest failed and 
                            # last_checked has a date, then specify last_alive as the
                            # date from first_found
                            ifelse(is.na(last_alive) & Fate == "1" & !is.na(last_checked),
                                   first_found,
                                   last_alive))) %>%
      # only keep rows that have 8 characters in the first_found, last_alive, and last_checked
      filter(nchar(first_found) == 8 & nchar(last_alive) == 8 & nchar(last_checked) == 8) %>%
      # specify date columns as a date string
      mutate(first_found2 = as.Date(paste(str_sub(first_found, 5, 8),
                                          str_sub(first_found, 3, 4),
                                          str_sub(first_found, 1, 2), sep = "-")),
             last_alive2 = as.Date(paste(str_sub(last_alive, 5, 8),
                                         str_sub(last_alive, 3, 4),
                                         str_sub(last_alive, 1, 2), sep = "-")),
             last_checked2 = as.Date(paste(str_sub(last_checked, 5, 8),
                                           str_sub(last_checked, 3, 4),
                                           str_sub(last_checked, 1, 2), sep = "-"))) %>%
      # if the found date is > days before the last alive date, and the clutch 
      # completion date is not NA and is < 40 days before the last alive date 
      # then replace the found date with the clutch completion date
      mutate(first_found2 = ifelse(!is.na(clutch_comp) & ((last_alive2 - first_found2) > 40 | (last_alive2 - first_found2) < 0)
                                                            & ((last_alive2 - clutch_comp) < 40 | (last_alive2 - clutch_comp) > 0), 
                                   clutch_comp, first_found2) %>% as.Date()) %>% 
      # if last checked date is before last alive date, then change it to the 
      # last alive date, if not then leave as is
      mutate(last_checked2 = ifelse(!is.na(last_alive2) & !is.na(last_checked2) & last_checked2 < last_alive2, 
                                    last_alive2, last_checked2) %>% as.Date()) %>% 
      # # julian dates
      # mutate(FirstFound = ((as.integer(format(first_found2, "%j")) -
      #                        as.integer(format(as.Date("2001-06-01"), "%j")) + 1) %% 365) %>%
      #      replace(. == 0, 365),#as.numeric(format(first_found2 + 180, "%j")),
      #        LastPresent = ((as.integer(format(last_alive2, "%j")) -
      #                        as.integer(format(as.Date("2001-06-01"), "%j")) + 1) %% 365) %>%
      #      replace(. == 0, 365),#as.numeric(format(last_alive2 + 180, "%j")),
      #        LastChecked = ((as.integer(format(last_checked2, "%j")) -
      #                        as.integer(format(as.Date("2001-06-01"), "%j")) + 1) %% 365) %>%
      #      replace(. == 0, 365)) %>% #as.numeric(format(last_checked2 + 180, "%j"))) %>% 
      # julian dates
      mutate(FirstFound = as.numeric(format(first_found2 + 180, "%j")),
             LastPresent = as.numeric(format(last_alive2 + 180, "%j")),
             LastChecked = as.numeric(format(last_checked2 + 180, "%j"))) %>% 
      # remove all nests that have unknown fate
      # filter(!is.na(Fate)) %>% 
      # clean up the management_type column
      mutate(management_type = tolower(management_type)) %>% 
      mutate(management_type = str_replace(management_type, "acess", "access")) %>% 
      mutate(management_type = str_replace(management_type, "and", ",")) %>% 
      mutate(management_type = str_replace(management_type, "temporary", "")) %>% 
      mutate(management_type = str_replace_all(management_type, " ", "")) %>% 
      mutate(management_type = str_replace_all(management_type, "shelters", "")) %>% 
      mutate(management_type = str_replace_all(management_type, "banners", "")) %>% 
      mutate(management_type = str_replace_all(management_type, ",,", ",")) %>% 
      mutate(sign_access = ifelse(str_detect(management_type, "signaccess"), 1, 0)) %>%
      mutate(perm_fence = ifelse(str_detect(management_type, "permanentfence") | str_detect(management_type, "ringlockfence"), 1, 0)) %>%
      mutate(sign_nest = ifelse(str_detect(management_type, "signnest"), 1, 0)) %>% 
      mutate(rope_fence = ifelse(str_detect(management_type, "ropefence"), 1, 0)) %>% 
      mutate(wardens = ifelse(str_detect(management_type, "wardens"), 1, 0)) %>% 
      mutate(none = ifelse(str_detect(management_type, "none"), 1, 
                           ifelse(is.na(management_type) & management_status == "N", 1, 0))) %>% 
      mutate(other = ifelse(str_detect(management_type, "other"), 1, 0)) %>%
      mutate(nest_hab = tolower(nest_hab)) %>% 
                                        # Level 4 is Sign Nest, Rope fence, Wardens
      mutate(management_level = ifelse(rope_fence == 1 & wardens == 1, 4,
                                       # Level 3 is Sign Nest, Rope fence
                                       ifelse(rope_fence == 1, 3, 
                                              # Level 2 is Sign Nest
                                              ifelse(sign_nest == 1, 2,
                                                     # Level 1 is Sign Access or Permanent fence (but only if nest in dune)
                                                     ifelse((perm_fence == 1 & nest_hab == "dune") | sign_access == 1, 1,
                                                            ifelse(none == 1, 0, NA))))))
  }

Importing and checking nest survival data

Mornington Peninsula

Flag potential issues in data

First we import the data and run a few checks to assess if there are any rows with the following issues:

  1. found date is not 8 characters

  2. last seen alive date is not 8 characters

  3. last checked date is not 8 characters

  4. found date missing

  5. last seen alive date missing

  6. last checked date missing

  7. Nest managed? is not Y or N

  8. Nest habitat is not Beach, Dune, Foredune/face, Estuary/spit, or Rocks

  9. Management type is not sufficient for making levels

  10. Double check dates because incubation time greater than 35 days

  11. Found date is after Last Alive date (should be greater or equal)

  12. Found date is after Last Checked date (should be greater or equal)

  13. Last Checked date is before Last Alive date (should be greater or equal)

Code
MP_nest_data_issues <-
suppressMessages(
  bind_rows(
  read_excel(paste0("data/", "MP Nesting Summary All Years_19062025.xlsx"), 
             sheet = paste0("MP", " ", "2023", "_", str_sub("2024", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "MP Nesting Summary All Years_19062025.xlsx"), 
             sheet = paste0("MP", " ", "2022", "_", str_sub("2023", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "MP Nesting Summary All Years_19062025.xlsx"), 
             sheet = paste0("MP", " ", "2021", "_", str_sub("2022", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "MP Nesting Summary All Years_19062025.xlsx"), 
             sheet = paste0("MP", " ", "2020", "_", str_sub("2021", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "MP Nesting Summary All Years_19062025.xlsx"), 
             sheet = paste0("MP", " ", "2019", "_", str_sub("2020", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "MP Nesting Summary All Years_19062025.xlsx"), 
             sheet = paste0("MP", " ", "2018", "_", str_sub("2019", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "MP Nesting Summary All Years_19062025.xlsx"), 
             sheet = paste0("MP", " ", "2017", "_", str_sub("2018", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "MP Nesting Summary All Years_19062025.xlsx"), 
             sheet = paste0("MP", " ", "2016", "_", str_sub("2017", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "MP Nesting Summary All Years_19062025.xlsx"), 
             sheet = paste0("MP", " ", "2015", "_", str_sub("2016", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "MP Nesting Summary All Years_19062025.xlsx"), 
             sheet = paste0("MP", " ", "2014", "_", str_sub("2015", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "MP Nesting Summary All Years_19062025.xlsx"), 
             sheet = paste0("MP", " ", "2013", "_", str_sub("2014", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "MP Nesting Summary All Years_19062025.xlsx"), 
             sheet = paste0("MP", " ", "2012", "_", str_sub("2013", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "MP Nesting Summary All Years_19062025.xlsx"), 
             sheet = paste0("MP", " ", "2011", "_", str_sub("2012", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "MP Nesting Summary All Years_19062025.xlsx"), 
             sheet = paste0("MP", " ", "2010", "_", str_sub("2011", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "MP Nesting Summary All Years_19062025.xlsx"), 
             sheet = paste0("MP", " ", "2009", "_", str_sub("2010", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "MP Nesting Summary All Years_19062025.xlsx"), 
             sheet = paste0("MP", " ", "2008", "_", str_sub("2009", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "MP Nesting Summary All Years_19062025.xlsx"), 
             sheet = paste0("MP", " ", "2007", "_", str_sub("2008", 3, 4)), 
             col_types = "text", na = "n/a"), 
  read_excel(paste0("data/", "MP Nesting Summary All Years_19062025.xlsx"), 
             sheet = paste0("MP", " ", "2006", "_", str_sub("2007", 3, 4)), 
             col_types = "text", na = "n/a"))) %>%
    filter(!is.na(Season)) %>% 
  rename(first_found = 13,
         last_alive = 33,
         last_checked = 39,
         Fate = `Hatch?`,
         season = Season,
         # site = Site,
         site = `Suggested update to site name`,
         nest_ID = `Nest ID`,
         nest_hab = `Nest habitat`,
         management_status = `Nest managed?`,
         management_type = `Management type`,
         nest_lat = `Nest latitude`,
         nest_lon = `Nest longitude`,
         state_1st_ob = `Age stage first observed`) %>% 
  rename(
    chick_1st_ob = !!names(.)[which(names(.) %in% c("Date chicks sighted", "Chicks first obsv date"))][1],
    clutch_comp  = !!names(.)[which(names(.) %in% c("Known clutch complete date", "Known laying date"))][1]
  ) %>% 
  # chick_1st_ob = which(names(.) %in% c("Date chicks sighted", "Chicks first obsv date"))[1],
  # clutch_comp = which(names(.) %in% c("Known clutch complete date", "Known laying date"))) %>% 
  dplyr::select(season, site, nest_ID, first_found, last_alive, last_checked, Fate, nest_hab, 
                management_status, management_type, nest_lat, nest_lon, site,
                chick_1st_ob, clutch_comp, state_1st_ob) %>%
  mutate(Fate = ifelse(Fate == "?", "Unk", Fate)) %>% 
  mutate(Fate = toupper(Fate)) %>% 
  filter(
    is.na(first_found) | 
      grepl("^\\s*-?\\d+(\\.\\d+)?\\s*$", first_found)
  ) %>%
  mutate(last_checked = ifelse(!is.na(last_checked) & !grepl("^\\s*-?\\d+(\\.\\d+)?\\s*$", last_checked), 
                               NA, last_checked)) %>% 
  mutate(last_alive = ifelse(!is.na(last_alive) & !grepl("^\\s*-?\\d+(\\.\\d+)?\\s*$", last_alive), 
                             NA, last_alive)) %>% 
  mutate(last_alive = ifelse(str_detect(last_alive, "Unk."), NA, last_alive),
         Fate = ifelse(Fate == "Y", 0, 
                       ifelse(Fate == "N", 1, 
                              ifelse(Fate == "UNK", NA, "XXX")))) %>%
  # remove nests without Fate information
  filter(Fate %in% c("0", "1")) %>% 
  mutate(chick_1st_ob = case_when(
    # Excel serial dates stored as numbers
    str_detect(chick_1st_ob, "^[0-9]+$") ~ as.Date(as.numeric(chick_1st_ob), origin = "1899-12-30"),
    
    # Dates with extra text in parentheses — extract only the date part
    str_detect(chick_1st_ob, "^\\d{1,2}/\\d{1,2}/\\d{2,4}") ~ suppressWarnings(
      dmy(str_extract(chick_1st_ob, "^\\d{1,2}/\\d{1,2}/\\d{2,4}"))
    ),
    
    # Everything else (including "Unk", "Failed during laying") → NA
    TRUE ~ as.Date(NA)
  ), 
  clutch_comp =  case_when(
    # Excel serial dates stored as numbers
    str_detect(clutch_comp, "^[0-9]+$") ~ as.Date(as.numeric(clutch_comp), origin = "1899-12-30"),
    
    # Dates with extra text in parentheses — extract only the date part
    str_detect(clutch_comp, "^\\d{1,2}/\\d{1,2}/\\d{2,4}") ~ suppressWarnings(
      dmy(str_extract(clutch_comp, "^\\d{1,2}/\\d{1,2}/\\d{2,4}"))
    ),
    
    # Everything else (including "Unk", "Failed during laying") → NA
    TRUE ~ as.Date(NA)
  )) %>%
  # if the clutch completion date is NA, then estimate it as 35 days before estimated hatch date
  # using the date of first chick observation and the size of the chicks when seen
  mutate(clutch_comp = ifelse(!is.na(clutch_comp), clutch_comp, 
                              ifelse(Fate == 0 & is.na(clutch_comp) & !is.na(chick_1st_ob) & !is.na(state_1st_ob),
                                     ifelse(state_1st_ob == "1/3 adult size, fluffy", chick_1st_ob - 3 - 35,
                                            ifelse(state_1st_ob == "1/2 adult size, fluffy", chick_1st_ob - 10 - 35,
                                                   ifelse(state_1st_ob == "2/3 adult size, fluffy", chick_1st_ob - 19 - 35,
                                                          ifelse(state_1st_ob == "Adult size, mottled grey", chick_1st_ob - 30 - 35,
                                                                 ifelse(state_1st_ob == "Fledged", chick_1st_ob - 35 - 35,
                                                                        ifelse(state_1st_ob == "wet in nest", chick_1st_ob - 35, NA)))))), 
                                     ifelse(Fate == 0 & is.na(clutch_comp) & !is.na(chick_1st_ob) & is.na(state_1st_ob), NA, NA))) %>% as.Date()) %>% 
  mutate(last_alive2 = ifelse(Fate == 0 & !is.na(clutch_comp) & is.na(last_alive), clutch_comp + 35,
                              ifelse(Fate == 0 & is.na(clutch_comp) & !is.na(chick_1st_ob) & !is.na(state_1st_ob) & is.na(last_alive),
                                     ifelse(state_1st_ob == "1/3 adult size, fluffy", chick_1st_ob - 3,
                                            ifelse(state_1st_ob == "1/2 adult size, fluffy", chick_1st_ob - 10,
                                                   ifelse(state_1st_ob == "2/3 adult size, fluffy", chick_1st_ob - 19,
                                                          ifelse(state_1st_ob == "Adult size, mottled grey", chick_1st_ob - 30,
                                                                 ifelse(state_1st_ob == "Fledged", chick_1st_ob - 35,
                                                                        ifelse(state_1st_ob == "wet in nest", chick_1st_ob, NA)))))), 
                                     ifelse(Fate == 0 & is.na(clutch_comp) & !is.na(chick_1st_ob) & is.na(state_1st_ob) & is.na(last_alive), NA, NA))) %>% as.Date()) %>% 
  # mutate(last_alive2 = ifelse(Fate == 0 & !is.na(chick_1st_ob) & last_alive2 > chick_1st_ob, chick_1st_ob, last_alive2) %>% as.Date()) %>% 
  mutate(last_alive = ifelse(!is.na(last_alive2), 
                             paste0(str_sub(as.character(last_alive2), 9, 10),
                                    str_sub(as.character(last_alive2), 6, 7),
                                    str_sub(as.character(last_alive2), 1, 4)), last_alive)) %>% 
  mutate(
    last_checked = ifelse(!is.na(last_alive) & is.na(last_checked),
                          last_alive,
                          ifelse(is.na(last_alive) & is.na(last_checked),
                                 first_found, last_checked))) %>%
  mutate(
    last_alive = ifelse(is.na(last_alive) & Fate == "0" & !is.na(last_checked),
                        last_checked,
                        ifelse(is.na(last_alive) & Fate == "1" & !is.na(last_checked),
                               first_found,
                               last_alive))) %>%
  filter(
    (is.na(last_alive) | nchar(last_alive) == 8) &
      (is.na(first_found) | nchar(first_found) == 8) &
      (is.na(last_checked) | nchar(last_checked) == 8)
  ) %>% 
  mutate(first_found2 = as.Date(paste(str_sub(first_found, 5, 8),
                                      str_sub(first_found, 3, 4),
                                      str_sub(first_found, 1, 2), sep = "-")),
         last_alive2 = as.Date(paste(str_sub(last_alive, 5, 8),
                                     str_sub(last_alive, 3, 4),
                                     str_sub(last_alive, 1, 2), sep = "-")),
         last_checked2 = as.Date(paste(str_sub(last_checked, 5, 8),
                                       str_sub(last_checked, 3, 4),
                                       str_sub(last_checked, 1, 2), sep = "-"))) %>% 
  mutate(last_checked2 = ifelse(!is.na(last_alive2) & !is.na(last_checked2) & last_checked2 < last_alive2, 
                                last_alive2, last_checked2) %>% as.Date()) %>% 
  mutate(first_found2 = ifelse(!is.na(clutch_comp) & ((last_alive2 - first_found2) > 40 | (last_alive2 - first_found2) < 0)
                               & ((last_alive2 - clutch_comp) < 40 | (last_alive2 - clutch_comp) > 0), 
                               clutch_comp, first_found2) %>% as.Date()) %>% 
  mutate(FirstFound = as.numeric(format(first_found2 + 180, "%j")),
         LastPresent = as.numeric(format(last_alive2 + 180, "%j")),
         LastChecked = as.numeric(format(last_checked2 + 180, "%j"))) %>% 
  # mutate(FirstFound = ((as.integer(format(first_found2, "%j")) -
  #                         as.integer(format(as.Date("2001-06-01"), "%j")) + 1) %% 365) %>%
  #          replace(. == 0, 365),#as.numeric(format(first_found2 + 180, "%j")),
  #        LastPresent = ((as.integer(format(last_alive2, "%j")) -
  #                          as.integer(format(as.Date("2001-06-01"), "%j")) + 1) %% 365) %>%
  #          replace(. == 0, 365),#as.numeric(format(last_alive2 + 180, "%j")),
  #        LastChecked = ((as.integer(format(last_checked2, "%j")) -
  #                          as.integer(format(as.Date("2001-06-01"), "%j")) + 1) %% 365) %>%
  #          replace(. == 0, 365)) %>% #as.numeric(format(last_checked2 + 180, "%j"))) %>% 
  mutate(management_type = tolower(management_type)) %>%
  mutate(nest_hab = tolower(nest_hab)) %>%
  mutate(management_type = str_replace(management_type, "acess", "access")) %>%
  mutate(management_type = str_replace(management_type, "and", ",")) %>%
  mutate(management_type = str_replace(management_type, "temporary", "")) %>%
  mutate(management_type = str_replace_all(management_type, " ", "")) %>%
  mutate(management_type = str_replace_all(management_type, "shelters", "")) %>%
  mutate(management_type = str_replace_all(management_type, "banners", "")) %>%
  mutate(management_type = str_replace_all(management_type, ",,", ",")) %>%
  mutate(sign_access = ifelse(str_detect(management_type, "signaccess"), 1, 0)) %>%
  mutate(sign_nest = ifelse(str_detect(management_type, "signnest"), 1, 0)) %>%
  mutate(rope_fence = ifelse(str_detect(management_type, "ropefence"), 1, 0)) %>%
  mutate(perm_fence = ifelse(str_detect(management_type, "permanentfence"), 1, 0)) %>% # & nest_hab == "dune", 1, 0)) %>%
  mutate(wardens = ifelse(str_detect(management_type, "wardens"), 1, 0)) %>% 
  mutate(none = ifelse(str_detect(management_type, "none"), 1, 
                       ifelse(is.na(management_type) & management_status == "N", 1, 0))) %>%
  mutate(other = ifelse(str_detect(management_type, "other"), 1, 0)) %>%
  mutate(management_level = ifelse((sign_access == 1 | perm_fence == 1) & sign_nest == 1 & rope_fence == 1 & wardens == 1, 4,
                                   ifelse(rope_fence == 1, 3,
                                          ifelse(sign_nest == 1, 2,
                                                 ifelse(sign_access == 1 | perm_fence == 1, 1,
                                                        ifelse(none == 1, 0, NA)))))) %>%
  mutate(sign_nest_no_sign_access = ifelse(sign_access == 0 & sign_nest == 1, 1, 0)) %>%
  mutate(fence_no_sign = ifelse((sign_access == 0 & sign_nest == 0) & rope_fence == 1, 1, 0)) %>%
  mutate(wardens_no_sign = ifelse((sign_access == 0 & sign_nest == 0) & wardens == 1, 1, 0)) %>%
  mutate(wardens_no_fence = ifelse(rope_fence == 1 & wardens == 1, 1, 0)) %>%
  mutate(just_wardens = ifelse(rope_fence == 0 & sign_access == 0 & sign_nest == 0 & wardens == 1, 1, 0)) %>%
  dplyr::select(-other, -sign_nest_no_sign_access, -fence_no_sign, 
                -wardens_no_sign, -wardens_no_fence, -just_wardens) %>%
  group_by(season) %>%
  mutate(nocc = max(max(LastChecked, na.rm = TRUE), max(LastPresent, na.rm = TRUE)),
         season = as.factor(season),
         nest_hab = as.factor(nest_hab),
         management_status = as.factor(management_status)) %>% 
  mutate(region = "MP") %>%
  mutate(site = as.factor(site)) %>%
  mutate(issue1 = ifelse(nchar(first_found) != 8, "found date is not 8 characters; ", NA)) %>% 
  mutate(issue2 = ifelse(nchar(last_alive) != 8, "last seen alive date is not 8 characters; ", NA)) %>% 
  mutate(issue3 = ifelse(nchar(last_checked) != 8, "last checked date is not 8 characters; ", NA)) %>% 
  mutate(issue4 = ifelse(is.na(first_found), "found date missing; ", NA)) %>% 
  mutate(issue5 = ifelse(is.na(last_alive), "last seen alive date missing; ", NA)) %>% 
  mutate(issue6 = ifelse(is.na(last_checked), "last checked date missing; ", NA)) %>% 
  mutate(issue7 = ifelse(management_status %!in% c("Y", "N"), "Nest managed? is not Y or N; ", NA)) %>% 
  mutate(issue8 = ifelse(nest_hab %!in% c("beach", "dune", "foredune/face", "estuary/spit", "rocks"), 
                         "Nest habitat is not beach, dune, foredune/face, estuary/spit, or rocks; ", NA)) %>% 
  mutate(issue9 = ifelse(is.na(management_level), "Management type is not sufficient for making levels; ", NA)) %>%
  mutate(found_and_alive_diff = last_alive2 - first_found2) %>% 
  mutate(issue10 = ifelse(found_and_alive_diff > 40 , "Double check dates because incubation time greater than 40 days; ", NA)) %>% 
  mutate(issue11 = ifelse(first_found2 > last_alive2, "Found date is after Last Alive date (should be greater or equal); ", NA)) %>% 
  mutate(issue12 = ifelse(first_found2 > last_checked2, "Found date is after Last Checked date (should be greater or equal); ", NA)) %>%
  mutate(issue13 = ifelse(last_checked2 < last_alive2, "Last Checked date is before Last Alive date (should be greater or equal); ", NA)) %>% 
  mutate(issues = ifelse(is.na(issue1) & is.na(issue2) & is.na(issue3) & 
                           is.na(issue4) & is.na(issue5) & is.na(issue6) & 
                           is.na(issue7) & is.na(issue8) & is.na(issue9) & 
                           is.na(issue10) & is.na(issue11) & is.na(issue12) & is.na(issue13), NA, 
                         paste0(issue1, issue2, issue3, 
                                issue4, issue5, issue6, 
                                issue7, issue8, issue9,
                                issue10, issue11, issue12, issue13))) %>% 
  mutate(issues = str_remove_all(issues, "NA")) %>% 
  mutate(issues = ifelse(is.na(issues), "usable", issues)) %>% 
  dplyr::select(-issue1, -issue2, -issue3, 
                -issue4, -issue5, -issue6, 
                -issue7, -issue8, -issue9, 
                -issue10, -issue11, -issue12, -issue13) %>% 
  filter(issues != "usable") %>%
  arrange(issues)
# 
# MP_nest_data_issues %>%
#   filter(str_detect(issues, "date")) %>%
#   select(nest_ID, Fate, clutch_comp, chick_1st_ob, first_found2, last_alive2, last_checked2, first_found, last_alive, last_checked, found_and_alive_diff, issues) %>% View()

all issues (probably most of these can’t be resolved)

Code
# Create a new workbook to store issues as two sheets
MP_nest_issues <- createWorkbook()

# Add all_issues sheet
addWorksheet(MP_nest_issues, "all_issues")

# view issues interactively in RStudio Viewer
MP_nest_data_issues %>%
  datatable(class = 'cell-border stripe', rownames = FALSE, filter = 'top')
Code
# write MP_nest_data_check
writeData(MP_nest_issues, sheet = "all_issues", MP_nest_data_issues)

date-specific issues (probably most of these CAN be resolved)

Code
# Add date_issues
addWorksheet(MP_nest_issues, "date_issues")

# view issues interactively in RStudio Viewer
MP_nest_data_issues %>% 
  filter(first_found != "Not found" & last_alive != "Not seen" & last_checked != "Not seen" & last_checked != "Not revisited") %>%
  filter(str_detect(issues, "date")) %>%
  mutate(issues = str_remove_all(issues, "Management type is not sufficient for making levels; ")) %>%
  mutate(issues = str_remove_all(issues, "Nest habitat is not Beach, Dune, Foredune/face, Estuary/spit, or Rocks; ")) %>%
  dplyr::select(season, nest_ID, nest_hab, first_found, first_found2, last_alive, last_alive2, last_checked, last_checked2, 
                Fate, found_and_alive_diff, issues)  %>%
  datatable(class = 'cell-border stripe', rownames = FALSE, filter = 'top')
Code
# write MP_nest_data_check
MP_nest_data_issues %>% 
  filter(first_found != "Not found" & last_alive != "Not seen" & last_checked != "Not seen" & last_checked != "Not revisited") %>%
  filter(str_detect(issues, "date")) %>%
  mutate(issues = str_remove_all(issues, "Management type is not sufficient for making levels; ")) %>%
  mutate(issues = str_remove_all(issues, "Nest habitat is not Beach, Dune, Foredune/face, Estuary/spit, or Rocks; ")) %>%
  dplyr::select(season, nest_ID, first_found, first_found2, last_alive, last_alive2, last_checked, last_checked2, 
                Fate, found_and_alive_diff, issues) %>% 
  writeData(MP_nest_issues, sheet = "date_issues", .)

# Save the workbook
saveWorkbook(MP_nest_issues,
             here("data/nest_issues_commented/MP_nest_data_issues_220825.xlsx"), overwrite = TRUE)

Import data

Code
nest_data_MP <-
  bind_rows(
    nest_import(year_1 = "2023", year_2 = "2024", 
                        file_name = "MP Nesting Summary All Years_19062025.xlsx", site = "MP",
                        first_found_date_col = 13, 
                        last_alive_date_col = 33, 
                        last_checked_col = 39),
    nest_import(year_1 = "2022", year_2 = "2023", 
                        file_name = "MP Nesting Summary All Years_19062025.xlsx", site = "MP",
                        first_found_date_col = 13, 
                        last_alive_date_col = 33, 
                        last_checked_col = 39),
    nest_import(year_1 = "2021", year_2 = "2022", 
                        file_name = "MP Nesting Summary All Years_19062025.xlsx", site = "MP",
                        first_found_date_col = 13, 
                        last_alive_date_col = 33, 
                        last_checked_col = 39),
    nest_import(year_1 = "2020", year_2 = "2021", 
                        file_name = "MP Nesting Summary All Years_19062025.xlsx", site = "MP",
                        first_found_date_col = 12, 
                        last_alive_date_col = 31, 
                        last_checked_col = 36),
    nest_import(year_1 = "2019", year_2 = "2020", 
                        file_name = "MP Nesting Summary All Years_19062025.xlsx", site = "MP",
                        first_found_date_col = 12, 
                        last_alive_date_col = 31, 
                        last_checked_col = 36),
    nest_import(year_1 = "2018", year_2 = "2019", 
                        file_name = "MP Nesting Summary All Years_19062025.xlsx", site = "MP",
                        first_found_date_col = 12, 
                        last_alive_date_col = 31, 
                        last_checked_col = 36),
    nest_import(year_1 = "2017", year_2 = "2018", 
                        file_name = "MP Nesting Summary All Years_19062025.xlsx", site = "MP",
                        first_found_date_col = 12, 
                        last_alive_date_col = 31, 
                        last_checked_col = 36),
    nest_import(year_1 = "2016", year_2 = "2017", 
                        file_name = "MP Nesting Summary All Years_19062025.xlsx", site = "MP",
                        first_found_date_col = 12, 
                        last_alive_date_col = 31, 
                        last_checked_col = 36),
    nest_import(year_1 = "2015", year_2 = "2016", 
                        file_name = "MP Nesting Summary All Years_19062025.xlsx", site = "MP",
                        first_found_date_col = 12, 
                        last_alive_date_col = 31, 
                        last_checked_col = 36),
    nest_import(year_1 = "2014", year_2 = "2015", 
                        file_name = "MP Nesting Summary All Years_19062025.xlsx", site = "MP",
                        first_found_date_col = 12, 
                        last_alive_date_col = 31, 
                        last_checked_col = 36),
    nest_import(year_1 = "2013", year_2 = "2014", 
                        file_name = "MP Nesting Summary All Years_19062025.xlsx", site = "MP",
                        first_found_date_col = 12, 
                        last_alive_date_col = 31, 
                        last_checked_col = 36),
    nest_import(year_1 = "2012", year_2 = "2013", 
                        file_name = "MP Nesting Summary All Years_19062025.xlsx", site = "MP",
                        first_found_date_col = 12, 
                        last_alive_date_col = 31, 
                        last_checked_col = 36),
    nest_import(year_1 = "2011", year_2 = "2012", 
                        file_name = "MP Nesting Summary All Years_19062025.xlsx", site = "MP",
                        first_found_date_col = 12, 
                        last_alive_date_col = 31, 
                        last_checked_col = 36),
    nest_import(year_1 = "2010", year_2 = "2011", 
                        file_name = "MP Nesting Summary All Years_19062025.xlsx", site = "MP",
                        first_found_date_col = 12, 
                        last_alive_date_col = 31, 
                        last_checked_col = 36),
    nest_import(year_1 = "2009", year_2 = "2010", 
                        file_name = "MP Nesting Summary All Years_19062025.xlsx", site = "MP",
                        first_found_date_col = 12, 
                        last_alive_date_col = 31, 
                        last_checked_col = 36),
    nest_import(year_1 = "2008", year_2 = "2009", 
                        file_name = "MP Nesting Summary All Years_19062025.xlsx", site = "MP",
                        first_found_date_col = 12, 
                        last_alive_date_col = 31, 
                        last_checked_col = 36),
    nest_import(year_1 = "2007", year_2 = "2008", 
                        file_name = "MP Nesting Summary All Years_19062025.xlsx", site = "MP",
                        first_found_date_col = 12, 
                        last_alive_date_col = 31, 
                        last_checked_col = 36),
    nest_import(year_1 = "2006", year_2 = "2007", 
                        file_name = "MP Nesting Summary All Years_19062025.xlsx", site = "MP",
                        first_found_date_col = 12, 
                        last_alive_date_col = 31, 
                        last_checked_col = 36)) %>% 
  group_by(season) %>% 
  mutate(nocc = max(max(LastChecked, na.rm = TRUE), max(LastPresent, na.rm = TRUE)),
         season = as.factor(season),
         nest_hab = as.factor(nest_hab),
         management_status = as.factor(management_status)) %>% 
  filter(!is.na(FirstFound) & !is.na(LastPresent) & !is.na(LastChecked)) %>% 
  filter(management_status %in% c("Y", "N")) %>% 
  filter(nest_hab %in% c("beach", "dune", "foredune/face", "estuary/spit", "rocks")) %>%
  filter(!is.na(management_level)) %>% # drops 5 nests that have permanentfence in beach or foredune habitat OR have only a nondogssign
  mutate(region = "MP") %>% 
  mutate(site = as.factor(site)) %>%
  group_by(season, site) %>%
  arrange(first_found2, .by_group = TRUE) %>%
  mutate(rank = row_number()) %>%
  ungroup() %>%
  mutate(nest_ID_new = paste(season, site, rank, sep = "_")) %>% 
  ungroup()

Visual inspections of data

Code
nest_data_MP_check <-
  nest_data_MP %>% 
  ungroup() %>% 
  mutate(first_found2_md = paste(format(first_found2 + 180, format = "%m"),
                                 format(first_found2 + 180, format = "%d"),
                                 sep = "-"),
         last_alive2_md = paste(format(last_alive2 + 180, format = "%m"),
                                format(last_alive2 + 180, format = "%d"),
                                sep = "-"),
         last_checked2_md = paste(format(last_checked2 + 180, format = "%m"),
                                  format(last_checked2 + 180, format = "%d"),
                                  sep = "-")) %>% 
  mutate(first_found2_trans = as.Date(paste("2020", first_found2_md, sep = "-"), format = "%Y-%m-%d") - 179,
         last_alive2_trans = as.Date(paste("2020", last_alive2_md, sep = "-"), format = "%Y-%m-%d") - 179,
         last_checked2_trans = as.Date(paste("2020", last_checked2_md, sep = "-"), format = "%Y-%m-%d") - 179) %>% 
  mutate(season_label = paste0(str_sub(season, 1, 4), " to ", str_sub(season, 5, 6)),
         Fate = as.factor(Fate))
Spatial distribution of data

Note that this map only shows data that are in a decimal degrees format (e.g., -38.31), NOT degree minute seconds (e.g., 38 27.59). The map is interactive, so click on an outlier to see its metadata. Note that all nests in the 200607 and 200708 seasons are missing coordinates

Code
nest_data_MP_sf <-
  nest_data_MP %>% 
  as.data.frame() %>% 
  mutate(nest_lon = as.numeric(nest_lon) %>% suppressWarnings(),
         nest_lat = as.numeric(nest_lat) %>% suppressWarnings()) %>% 
  filter(!is.na(nest_lon) & !is.na(nest_lat)) %>%
  st_as_sf(coords = c("nest_lon", "nest_lat"), 
           crs = 4326)

mapview(nest_data_MP_sf,
        zcol = "season", 
        popup = popupTable(nest_data_MP_sf,
                           zcol = c("season",
                                    "site",
                                    "nest_ID")))
Year-specific Found Date Distributions
Code
ggplot(nest_data_MP_check, aes(first_found2_trans, fill = Fate)) +
  geom_histogram(bins = 30,
                 alpha = 0.8, color = "white", linewidth = 0.2) +
  scale_fill_manual(values = c("1" = brewer.pal(8, "Set1")[c(1)], "0" = brewer.pal(8, "Set1")[c(2)]),
                    name = "Nest Fate",
                    labels = c("Hatched", "Failed")) +
  ylab("weekly number of nests") +
  scale_x_date(date_labels = "%B", 
               # expand = c(0.01, 0.01), 
               date_breaks = "1 months", limits = c(min(nest_data_MP_check$first_found2_trans, na.rm = TRUE), 
                                                    max(nest_data_MP_check$last_checked2_trans, na.rm = TRUE))) +
  facet_wrap("season_label") +
  scale_y_continuous(limits = c(0, 12), breaks = c(2, 4, 6, 8, 10, 12)) +
  luke_theme +
  xlab("Found date") +
  theme(legend.position = "top",
        panel.grid.major = element_line(colour = "grey70", 
                                        size = 0.15),
        axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5))

Year-specific Last Alive Date Distributions
Code
ggplot(nest_data_MP_check, aes(last_alive2_trans, fill = as.factor(Fate))) +
  geom_histogram(bins = 30,
                 alpha = 0.8, color = "white", linewidth = 0.2) +
  scale_fill_manual(values = c("1" = brewer.pal(8, "Set1")[c(1)], "0" = brewer.pal(8, "Set1")[c(2)]),
                    name = "Nest Fate",
                    labels = c("Hatched", "Failed")) +
  ylab("weekly number of nests") +
  scale_x_date(date_labels = "%B", 
               expand = c(0.01, 0.01), 
               date_breaks = "1 months", limits = c(min(nest_data_MP_check$first_found2_trans, na.rm = TRUE), 
                                                    max(nest_data_MP_check$last_checked2_trans, na.rm = TRUE))) +
  facet_wrap("season_label") +
  scale_y_continuous(limits = c(0, 12), breaks = c(2, 4, 6, 8, 10, 12)) +
  luke_theme +
  xlab("Last alive date") +
  theme(legend.position = "top",
        panel.grid.major = element_line(colour = "grey70", 
                                        size = 0.15),
        axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5))

Year-specific Last Checked Date Distributions
Code
ggplot(nest_data_MP_check, aes(last_checked2_trans, fill = as.factor(Fate))) +
  geom_histogram(bins = 30,
                 alpha = 0.8, color = "white", linewidth = 0.2) +
  scale_fill_manual(values = c("1" = brewer.pal(8, "Set1")[c(1)], "0" = brewer.pal(8, "Set1")[c(2)]),
                    name = "Nest Fate",
                    labels = c("Hatched", "Failed")) +
  ylab("weekly number of nests") +
  scale_x_date(date_labels = "%B",
               expand = c(0.01, 0.01),
               date_breaks = "1 months", limits = c(min(nest_data_MP_check$first_found2_trans, na.rm = TRUE),
                                                    max(nest_data_MP_check$last_checked2_trans, na.rm = TRUE))) +
  facet_wrap("season_label") +
  scale_y_continuous(limits = c(0, 12), breaks = c(2, 4, 6, 8, 10, 12)) +
  luke_theme +
  xlab("Last checked date") +
  theme(legend.position = "top",
        panel.grid.major = element_line(colour = "grey70", 
                                        size = 0.15),
        axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5))

Tally number of nests per year in the dataset
Code
nest_data_MP_check %>% 
  group_by(season) %>%
  summarise(n())
# A tibble: 18 × 2
   season `n()`
   <fct>  <int>
 1 200607    18
 2 200708    31
 3 200809    18
 4 200910    23
 5 201011    45
 6 201112    43
 7 201213    48
 8 201314    46
 9 201415    61
10 201516    76
11 201617    93
12 201718    65
13 201819    64
14 201920    61
15 202021    78
16 202122    88
17 202223    81
18 202324    92
Code
# Total number of nests acorss all years
nest_data_MP_check %>% 
  summarise(n())
# A tibble: 1 × 1
  `n()`
  <int>
1  1031
Incubation length distribution
Code
# assess if there are nests with unusually long incubation periods
nest_data_MP_check %>% 
  mutate(found_and_alive_diff = last_alive2 - first_found2) %>%
  arrange(desc(found_and_alive_diff)) %>% 
  filter(first_found2 < last_alive2 & first_found2 < last_checked2 & found_and_alive_diff < 100) %>% 
  ggplot() +
  geom_histogram(aes(found_and_alive_diff)) +
  luke_theme +
  xlab("Time between found date and last alive date (days)") +
  ylab("Frquency of nests")

# A tibble: 0 × 33
# ℹ 33 variables: season <fct>, site <fct>, nest_ID <chr>, first_found <chr>,
#   last_alive <chr>, last_checked <chr>, Fate <chr>, nest_hab <fct>,
#   management_status <fct>, management_type <chr>, nest_lat <chr>,
#   nest_lon <chr>, chick_1st_ob <date>, clutch_comp <date>,
#   state_1st_ob <chr>, last_alive2 <date>, first_found2 <date>,
#   last_checked2 <date>, FirstFound <dbl>, LastPresent <dbl>,
#   LastChecked <dbl>, sign_access <dbl>, perm_fence <dbl>, sign_nest <dbl>, …
# A tibble: 0 × 33
# ℹ 33 variables: season <fct>, site <fct>, nest_ID <chr>, first_found <chr>,
#   last_alive <chr>, last_checked <chr>, Fate <chr>, nest_hab <fct>,
#   management_status <fct>, management_type <chr>, nest_lat <chr>,
#   nest_lon <chr>, chick_1st_ob <date>, clutch_comp <date>,
#   state_1st_ob <chr>, last_alive2 <date>, first_found2 <date>,
#   last_checked2 <date>, FirstFound <dbl>, LastPresent <dbl>,
#   LastChecked <dbl>, sign_access <dbl>, perm_fence <dbl>, sign_nest <dbl>, …
# A tibble: 0 × 33
# ℹ 33 variables: season <fct>, site <fct>, nest_ID <chr>, first_found <chr>,
#   last_alive <chr>, last_checked <chr>, Fate <chr>, nest_hab <fct>,
#   management_status <fct>, management_type <chr>, nest_lat <chr>,
#   nest_lon <chr>, chick_1st_ob <date>, clutch_comp <date>,
#   state_1st_ob <chr>, last_alive2 <date>, first_found2 <date>,
#   last_checked2 <date>, FirstFound <dbl>, LastPresent <dbl>,
#   LastChecked <dbl>, sign_access <dbl>, perm_fence <dbl>, sign_nest <dbl>, …
.
Double check dates because incubation time greater than 41 days;  
                                                                2 
# A tibble: 2 × 10
  found_and_alive_diff season nest_ID     first_found2 last_alive2 last_checked2
  <drtn>               <fct>  <chr>       <date>       <date>      <date>       
1 59 days              201213 201213_Moa… 2012-12-18   2013-02-15  2013-02-21   
2 52 days              201112 201112_Moa… 2011-12-27   2012-02-17  2012-02-22   
# ℹ 4 more variables: Fate <chr>, clutch_comp <date>, chick_1st_ob <date>,
#   state_1st_ob <chr>

Fleurieu Peninsula

Flag potential issues in data

As above, first we import the data and run a few checks to assess if there are any rows with the issues listed above

Code
FP_nest_data_issues <- 
suppressMessages(
  bind_rows(
  read_excel(paste0("data/", "FP Nesting summary_All years_30062025.xlsx"), 
             sheet = paste0("FP", " ", "2023", "_", str_sub("2024", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "FP Nesting summary_All years_30062025.xlsx"), 
             sheet = paste0("FP", " ", "2022", "_", str_sub("2023", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "FP Nesting summary_All years_30062025.xlsx"), 
             sheet = paste0("FP", " ", "2021", "_", str_sub("2022", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "FP Nesting summary_All years_30062025.xlsx"), 
             sheet = paste0("FP", " ", "2020", "_", str_sub("2021", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "FP Nesting summary_All years_30062025.xlsx"), 
             sheet = paste0("FP", " ", "2019", "_", str_sub("2020", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "FP Nesting summary_All years_30062025.xlsx"), 
             sheet = paste0("FP", " ", "2018", "_", str_sub("2019", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "FP Nesting summary_All years_30062025.xlsx"), 
             sheet = paste0("FP", " ", "2017", "_", str_sub("2018", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "FP Nesting summary_All years_30062025.xlsx"), 
             sheet = paste0("FP", " ", "2016", "_", str_sub("2017", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "FP Nesting summary_All years_30062025.xlsx"), 
             sheet = paste0("FP", " ", "2015", "_", str_sub("2016", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "FP Nesting summary_All years_30062025.xlsx"), 
             sheet = paste0("FP", " ", "2014", "_", str_sub("2015", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "FP Nesting summary_All years_30062025.xlsx"), 
             sheet = paste0("FP", " ", "2013", "_", str_sub("2014", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "FP Nesting summary_All years_30062025.xlsx"), 
             sheet = paste0("FP", " ", "2012", "_", str_sub("2013", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "FP Nesting summary_All years_30062025.xlsx"), 
             sheet = paste0("FP", " ", "2011", "_", str_sub("2012", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "FP Nesting summary_All years_30062025.xlsx"), 
             sheet = paste0("FP", " ", "2010", "_", str_sub("2011", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "FP Nesting summary_All years_30062025.xlsx"), 
             sheet = paste0("FP", " ", "2009", "_", str_sub("2010", 3, 4)), 
             col_types = "text", na = "n/a"))) %>% 
    filter(!is.na(Season)) %>% 
  rename(first_found = 13,
         last_alive = 33,
         last_checked = 39,
         Fate = `Hatch?`,
         season = Season,
         # site = Site,
         site = `Suggested update to site name`,
         nest_ID = `Nest ID`,
         nest_hab = `Nest habitat`,
         management_status = `Nest managed?`,
         management_type = `Management type`,
         nest_lat = `Nest latitude`,
         nest_lon = `Nest longitude`,
         state_1st_ob = `Age stage first observed`) %>% 
  rename(
    chick_1st_ob = !!names(.)[which(names(.) %in% c("Date chicks sighted", "Chicks first obsv date"))][1],
    clutch_comp  = !!names(.)[which(names(.) %in% c("Known clutch complete date", "Known laying date"))][1]
  ) %>% 
  # chick_1st_ob = which(names(.) %in% c("Date chicks sighted", "Chicks first obsv date"))[1],
  # clutch_comp = which(names(.) %in% c("Known clutch complete date", "Known laying date"))) %>% 
  dplyr::select(season, site, nest_ID, first_found, last_alive, last_checked, Fate, nest_hab, 
                management_status, management_type, nest_lat, nest_lon, site,
                chick_1st_ob, clutch_comp, state_1st_ob) %>%
  mutate(Fate = ifelse(Fate == "?", "Unk", Fate)) %>% 
  mutate(Fate = toupper(Fate)) %>% 
  filter(
    is.na(first_found) | 
      grepl("^\\s*-?\\d+(\\.\\d+)?\\s*$", first_found)
  ) %>%
  mutate(last_checked = ifelse(!is.na(last_checked) & !grepl("^\\s*-?\\d+(\\.\\d+)?\\s*$", last_checked), 
                               NA, last_checked)) %>% 
  mutate(last_alive = ifelse(!is.na(last_alive) & !grepl("^\\s*-?\\d+(\\.\\d+)?\\s*$", last_alive), 
                             NA, last_alive)) %>% 
  mutate(last_alive = ifelse(str_detect(last_alive, "Unk."), NA, last_alive),
         Fate = ifelse(Fate == "Y", 0, 
                       ifelse(Fate == "N", 1, 
                              ifelse(Fate == "UNK", NA, "XXX")))) %>%
  # remove nests without Fate information
  filter(Fate %in% c("0", "1")) %>% 
  mutate(chick_1st_ob = case_when(
    # Excel serial dates stored as numbers
    str_detect(chick_1st_ob, "^[0-9]+$") ~ as.Date(as.numeric(chick_1st_ob), origin = "1899-12-30"),
    
    # Dates with extra text in parentheses — extract only the date part
    str_detect(chick_1st_ob, "^\\d{1,2}/\\d{1,2}/\\d{2,4}") ~ suppressWarnings(
      dmy(str_extract(chick_1st_ob, "^\\d{1,2}/\\d{1,2}/\\d{2,4}"))
    ),
    
    # Everything else (including "Unk", "Failed during laying") → NA
    TRUE ~ as.Date(NA)
  ), 
  clutch_comp =  case_when(
    # Excel serial dates stored as numbers
    str_detect(clutch_comp, "^[0-9]+$") ~ as.Date(as.numeric(clutch_comp), origin = "1899-12-30"),
    
    # Dates with extra text in parentheses — extract only the date part
    str_detect(clutch_comp, "^\\d{1,2}/\\d{1,2}/\\d{2,4}") ~ suppressWarnings(
      dmy(str_extract(clutch_comp, "^\\d{1,2}/\\d{1,2}/\\d{2,4}"))
    ),
    
    # Everything else (including "Unk", "Failed during laying") → NA
    TRUE ~ as.Date(NA)
  )) %>%
  # if the clutch completion date is NA, then estimate it as 35 days before estimated hatch date
  # using the date of first chick observation and the size of the chicks when seen
  mutate(clutch_comp = ifelse(!is.na(clutch_comp), clutch_comp, 
                              ifelse(Fate == 0 & is.na(clutch_comp) & !is.na(chick_1st_ob) & !is.na(state_1st_ob),
                                     ifelse(state_1st_ob == "1/3 adult size, fluffy", chick_1st_ob - 3 - 35,
                                            ifelse(state_1st_ob == "1/2 adult size, fluffy", chick_1st_ob - 10 - 35,
                                                   ifelse(state_1st_ob == "2/3 adult size, fluffy", chick_1st_ob - 19 - 35,
                                                          ifelse(state_1st_ob == "Adult size, mottled grey", chick_1st_ob - 30 - 35,
                                                                 ifelse(state_1st_ob == "Fledged", chick_1st_ob - 35 - 35,
                                                                        ifelse(state_1st_ob == "wet in nest", chick_1st_ob - 35, NA)))))), 
                                     ifelse(Fate == 0 & is.na(clutch_comp) & !is.na(chick_1st_ob) & is.na(state_1st_ob), NA, NA))) %>% as.Date()) %>% 
  mutate(last_alive2 = ifelse(Fate == 0 & !is.na(clutch_comp) & is.na(last_alive), clutch_comp + 35,
                              ifelse(Fate == 0 & is.na(clutch_comp) & !is.na(chick_1st_ob) & !is.na(state_1st_ob) & is.na(last_alive),
                                     ifelse(state_1st_ob == "1/3 adult size, fluffy", chick_1st_ob - 3,
                                            ifelse(state_1st_ob == "1/2 adult size, fluffy", chick_1st_ob - 10,
                                                   ifelse(state_1st_ob == "2/3 adult size, fluffy", chick_1st_ob - 19,
                                                          ifelse(state_1st_ob == "Adult size, mottled grey", chick_1st_ob - 30,
                                                                 ifelse(state_1st_ob == "Fledged", chick_1st_ob - 35,
                                                                        ifelse(state_1st_ob == "wet in nest", chick_1st_ob, NA)))))), 
                                     ifelse(Fate == 0 & is.na(clutch_comp) & !is.na(chick_1st_ob) & is.na(state_1st_ob) & is.na(last_alive), NA, NA))) %>% as.Date()) %>% 
  # mutate(last_alive2 = ifelse(Fate == 0 & !is.na(chick_1st_ob) & last_alive2 > chick_1st_ob, chick_1st_ob, last_alive2) %>% as.Date()) %>% 
  mutate(last_alive = ifelse(!is.na(last_alive2), 
                             paste0(str_sub(as.character(last_alive2), 9, 10),
                                    str_sub(as.character(last_alive2), 6, 7),
                                    str_sub(as.character(last_alive2), 1, 4)), last_alive)) %>% 
  mutate(
    last_checked = ifelse(!is.na(last_alive) & is.na(last_checked),
                          last_alive,
                          ifelse(is.na(last_alive) & is.na(last_checked),
                                 first_found, last_checked))) %>%
  mutate(
    last_alive = ifelse(is.na(last_alive) & Fate == "0" & !is.na(last_checked),
                        last_checked,
                        ifelse(is.na(last_alive) & Fate == "1" & !is.na(last_checked),
                               first_found,
                               last_alive))) %>%
  filter(
    (is.na(last_alive) | nchar(last_alive) == 8) &
      (is.na(first_found) | nchar(first_found) == 8) &
      (is.na(last_checked) | nchar(last_checked) == 8)
  ) %>% 
  mutate(first_found2 = as.Date(paste(str_sub(first_found, 5, 8),
                                      str_sub(first_found, 3, 4),
                                      str_sub(first_found, 1, 2), sep = "-")),
         last_alive2 = as.Date(paste(str_sub(last_alive, 5, 8),
                                     str_sub(last_alive, 3, 4),
                                     str_sub(last_alive, 1, 2), sep = "-")),
         last_checked2 = as.Date(paste(str_sub(last_checked, 5, 8),
                                       str_sub(last_checked, 3, 4),
                                       str_sub(last_checked, 1, 2), sep = "-"))) %>% 
  mutate(last_checked2 = ifelse(!is.na(last_alive2) & !is.na(last_checked2) & last_checked2 < last_alive2, 
                                last_alive2, last_checked2) %>% as.Date()) %>% 
  mutate(first_found2 = ifelse(!is.na(clutch_comp) & ((last_alive2 - first_found2) > 40 | (last_alive2 - first_found2) < 0)
                               & ((last_alive2 - clutch_comp) < 40 | (last_alive2 - clutch_comp) > 0), 
                               clutch_comp, first_found2) %>% as.Date()) %>% 
  mutate(FirstFound = as.numeric(format(first_found2 + 180, "%j")),
         LastPresent = as.numeric(format(last_alive2 + 180, "%j")),
         LastChecked = as.numeric(format(last_checked2 + 180, "%j"))) %>% 
  # mutate(FirstFound = ((as.integer(format(first_found2, "%j")) -
  #                         as.integer(format(as.Date("2001-06-01"), "%j")) + 1) %% 365) %>%
  #          replace(. == 0, 365),#as.numeric(format(first_found2 + 180, "%j")),
  #        LastPresent = ((as.integer(format(last_alive2, "%j")) -
  #                          as.integer(format(as.Date("2001-06-01"), "%j")) + 1) %% 365) %>%
  #          replace(. == 0, 365),#as.numeric(format(last_alive2 + 180, "%j")),
  #        LastChecked = ((as.integer(format(last_checked2, "%j")) -
  #                          as.integer(format(as.Date("2001-06-01"), "%j")) + 1) %% 365) %>%
  #          replace(. == 0, 365)) %>% #as.numeric(format(last_checked2 + 180, "%j"))) %>% 
  mutate(management_type = tolower(management_type)) %>%
  mutate(nest_hab = tolower(nest_hab)) %>%
  mutate(management_type = str_replace(management_type, "acess", "access")) %>%
  mutate(management_type = str_replace(management_type, "and", ",")) %>%
  mutate(management_type = str_replace(management_type, "temporary", "")) %>%
  mutate(management_type = str_replace_all(management_type, " ", "")) %>%
  mutate(management_type = str_replace_all(management_type, "shelters", "")) %>%
  mutate(management_type = str_replace_all(management_type, "banners", "")) %>%
  mutate(management_type = str_replace_all(management_type, ",,", ",")) %>%
  mutate(sign_access = ifelse(str_detect(management_type, "signaccess"), 1, 0)) %>%
  mutate(sign_nest = ifelse(str_detect(management_type, "signnest"), 1, 0)) %>%
  mutate(rope_fence = ifelse(str_detect(management_type, "ropefence"), 1, 0)) %>%
  mutate(perm_fence = ifelse(str_detect(management_type, "permanentfence"), 1, 0)) %>% # & nest_hab == "dune", 1, 0)) %>%
  mutate(wardens = ifelse(str_detect(management_type, "wardens"), 1, 0)) %>% 
  mutate(none = ifelse(str_detect(management_type, "none"), 1, 
                       ifelse(is.na(management_type) & management_status == "N", 1, 0))) %>%
  mutate(other = ifelse(str_detect(management_type, "other"), 1, 0)) %>%
  mutate(management_level = ifelse((sign_access == 1 | perm_fence == 1) & sign_nest == 1 & rope_fence == 1 & wardens == 1, 4,
                                   ifelse(rope_fence == 1, 3,
                                          ifelse(sign_nest == 1, 2,
                                                 ifelse(sign_access == 1 | perm_fence == 1, 1,
                                                        ifelse(none == 1, 0, NA)))))) %>%
  mutate(sign_nest_no_sign_access = ifelse(sign_access == 0 & sign_nest == 1, 1, 0)) %>%
  mutate(fence_no_sign = ifelse((sign_access == 0 & sign_nest == 0) & rope_fence == 1, 1, 0)) %>%
  mutate(wardens_no_sign = ifelse((sign_access == 0 & sign_nest == 0) & wardens == 1, 1, 0)) %>%
  mutate(wardens_no_fence = ifelse(rope_fence == 1 & wardens == 1, 1, 0)) %>%
  mutate(just_wardens = ifelse(rope_fence == 0 & sign_access == 0 & sign_nest == 0 & wardens == 1, 1, 0)) %>%
  dplyr::select(-other, -sign_nest_no_sign_access, -fence_no_sign, 
                -wardens_no_sign, -wardens_no_fence, -just_wardens) %>%
  group_by(season) %>%
  mutate(nocc = max(max(LastChecked, na.rm = TRUE), max(LastPresent, na.rm = TRUE)),
         season = as.factor(season),
         nest_hab = as.factor(nest_hab),
         management_status = as.factor(management_status)) %>% 
  mutate(region = "MP") %>%
  mutate(site = as.factor(site)) %>%
  mutate(issue1 = ifelse(nchar(first_found) != 8, "found date is not 8 characters; ", NA)) %>% 
  mutate(issue2 = ifelse(nchar(last_alive) != 8, "last seen alive date is not 8 characters; ", NA)) %>% 
  mutate(issue3 = ifelse(nchar(last_checked) != 8, "last checked date is not 8 characters; ", NA)) %>% 
  mutate(issue4 = ifelse(is.na(first_found), "found date missing; ", NA)) %>% 
  mutate(issue5 = ifelse(is.na(last_alive), "last seen alive date missing; ", NA)) %>% 
  mutate(issue6 = ifelse(is.na(last_checked), "last checked date missing; ", NA)) %>% 
  mutate(issue7 = ifelse(management_status %!in% c("Y", "N"), "Nest managed? is not Y or N; ", NA)) %>% 
  mutate(issue8 = ifelse(nest_hab %!in% c("beach", "dune", "foredune/face", "estuary/spit", "rocks"), 
                         "Nest habitat is not beach, dune, foredune/face, estuary/spit, or rocks; ", NA)) %>% 
  mutate(issue9 = ifelse(is.na(management_level), "Management type is not sufficient for making levels; ", NA)) %>%
  mutate(found_and_alive_diff = last_alive2 - first_found2) %>% 
  mutate(issue10 = ifelse(found_and_alive_diff > 40 , "Double check dates because incubation time greater than 40 days; ", NA)) %>% 
  mutate(issue11 = ifelse(first_found2 > last_alive2, "Found date is after Last Alive date (should be greater or equal); ", NA)) %>% 
  mutate(issue12 = ifelse(first_found2 > last_checked2, "Found date is after Last Checked date (should be greater or equal); ", NA)) %>%
  mutate(issue13 = ifelse(last_checked2 < last_alive2, "Last Checked date is before Last Alive date (should be greater or equal); ", NA)) %>% 
  mutate(issues = ifelse(is.na(issue1) & is.na(issue2) & is.na(issue3) & 
                           is.na(issue4) & is.na(issue5) & is.na(issue6) & 
                           is.na(issue7) & is.na(issue8) & is.na(issue9) & 
                           is.na(issue10) & is.na(issue11) & is.na(issue12) & is.na(issue13), NA, 
                         paste0(issue1, issue2, issue3, 
                                issue4, issue5, issue6, 
                                issue7, issue8, issue9,
                                issue10, issue11, issue12, issue13))) %>% 
  mutate(issues = str_remove_all(issues, "NA")) %>% 
  mutate(issues = ifelse(is.na(issues), "usable", issues)) %>% 
  dplyr::select(-issue1, -issue2, -issue3, 
                -issue4, -issue5, -issue6, 
                -issue7, -issue8, -issue9, 
                -issue10, -issue11, -issue12, -issue13) %>% 
  filter(issues != "usable") %>%
  arrange(issues)

all issues (probably most of these can’t be resolved)

Code
# Create a new workbook to store issues as two sheets
FP_nest_issues <- createWorkbook()

# Add all_issues sheet
addWorksheet(FP_nest_issues, "all_issues")

# view issues interactively in RStudio Viewer
FP_nest_data_issues %>%
  datatable(class = 'cell-border stripe', rownames = FALSE, filter = 'top')
Code
# write FP_nest_data_check
writeData(FP_nest_issues, sheet = "all_issues", FP_nest_data_issues)

date-specific issues (probably most of these CAN be resolved)

Code
# Add date_issues
addWorksheet(FP_nest_issues, "date_issues")

# there are some blank (but non-NA) observations of management_type
FP_nest_data_issues %>% filter(is.na(management_type))
# A tibble: 18 × 32
# Groups:   season [1]
   season site        nest_ID first_found last_alive last_checked Fate  nest_hab
   <fct>  <fct>       <chr>   <chr>       <chr>      <chr>        <chr> <fct>   
 1 202223 Aldinga     202223… 06102022    06102022   06102022     1     beach   
 2 202223 Ballaparud… 202223… 24112022    24112022   05122022     1     beach   
 3 202223 Callawonga  202223… 06012023    06012023   24012023     1     beach   
 4 202223 Moana Beac… 202223… 11102022    13102022   14102022     1     beach   
 5 202223 Myponga Be… 202223… 05112022    06112022   07112022     1     estuary…
 6 202223 Ochre Cove… 202223… 19102022    20102022   21102022     1     foredun…
 7 202223 Parsons Be… 202223… 09122022    09122022   11122022     1     beach   
 8 202223 Port Willu… 202223… 13092022    14092022   17092022     1     beach   
 9 202223 Tunkalilla… 202223… 01102022    01102022   09102022     1     beach   
10 202223 Tunkalilla… 202223… 09012023    09012023   29012023     1     beach   
11 202223 Tunkalilla… 202223… 29012023    29012023   07022023     1     beach   
12 202223 Tunkalilla… 202223… 07112022    17112022   30112022     1     foredun…
13 202223 Tunkalilla… 202223… 17112022    17112022   30112022     1     dune    
14 202223 Tunkalilla… 202223… 17112022    17112022   30112022     1     foredun…
15 202223 Waitpinga … 202223… 26102022    26102022   05112022     1     beach   
16 202223 Waitpinga … 202223… 05112022    05112022   22112022     1     beach   
17 202223 Yankalilla… 202223… 01092022    02092022   02092022     1     beach   
18 202223 Yankalilla… 202223… 30092022    30092022   30092022     1     estuary…
# ℹ 24 more variables: management_status <fct>, management_type <chr>,
#   nest_lat <chr>, nest_lon <chr>, chick_1st_ob <date>, clutch_comp <date>,
#   state_1st_ob <chr>, last_alive2 <date>, first_found2 <date>,
#   last_checked2 <date>, FirstFound <dbl>, LastPresent <dbl>,
#   LastChecked <dbl>, sign_access <dbl>, sign_nest <dbl>, rope_fence <dbl>,
#   perm_fence <dbl>, wardens <dbl>, none <dbl>, management_level <dbl>,
#   nocc <dbl>, region <chr>, found_and_alive_diff <drtn>, issues <chr>
Code
# view issues interactively in RStudio Viewer
FP_nest_data_issues %>% 
  filter(first_found != "Not found" & last_alive != "Not seen" & last_checked != "Not seen" & last_checked != "Not revisited") %>%
  filter(str_detect(issues, "date")) %>%
  mutate(issues = str_remove_all(issues, "Management type is not sufficient for making levels; ")) %>%
  mutate(issues = str_remove_all(issues, "Nest habitat is not beach, dune, foredune/face, estuary/spit, or rocks; ")) %>%
  dplyr::select(season, nest_ID, nest_hab, first_found, first_found2, last_alive, last_alive2, last_checked, last_checked2, 
                Fate, found_and_alive_diff, issues)  %>%
  datatable(class = 'cell-border stripe', rownames = FALSE, filter = 'top')
Code
# write FP_nest_data_check
FP_nest_data_issues %>% 
  filter(first_found != "Not found" & last_alive != "Not seen" & last_checked != "Not seen" & last_checked != "Not revisited") %>%
  filter(str_detect(issues, "date")) %>%
  mutate(issues = str_remove_all(issues, "Management type is not sufficient for making levels; ")) %>%
  mutate(issues = str_remove_all(issues, "Nest habitat is not Beach, Dune, Foredune/face, Estuary/spit, or Rocks; ")) %>%
  dplyr::select(season, nest_ID, first_found, first_found2, last_alive, last_alive2, last_checked, last_checked2, 
                Fate, found_and_alive_diff, issues) %>% 
  writeData(FP_nest_issues, sheet = "date_issues", .)

# Save the workbook
saveWorkbook(FP_nest_issues, here("data/nest_issues_commented/FP_nest_data_issues_280525.xlsx"), overwrite = TRUE)

Import data

Code
nest_data_FP <-
  bind_rows(
    nest_import(year_1 = "2023", year_2 = "2024", 
                        file_name = "FP Nesting summary_All years_30062025.xlsx", site = "FP",
                        first_found_date_col = 13, 
                        last_alive_date_col = 33, 
                        last_checked_col = 39),
    nest_import(year_1 = "2022", year_2 = "2023", 
                        file_name = "FP Nesting summary_All years_30062025.xlsx", site = "FP",
                        first_found_date_col = 13, 
                        last_alive_date_col = 33, 
                        last_checked_col = 39),
    nest_import(year_1 = "2021", year_2 = "2022", 
                        file_name = "FP Nesting summary_All years_30062025.xlsx", site = "FP",
                        first_found_date_col = 13, 
                        last_alive_date_col = 33, 
                        last_checked_col = 39),
    nest_import(year_1 = "2020", year_2 = "2021", 
                        file_name = "FP Nesting summary_All years_30062025.xlsx", site = "FP",
                        first_found_date_col = 12, 
                        last_alive_date_col = 33, 
                        last_checked_col = 40),
    nest_import(year_1 = "2019", year_2 = "2020", 
                        file_name = "FP Nesting summary_All years_30062025.xlsx", site = "FP", 
                        first_found_date_col = 12, 
                        last_alive_date_col = 33, 
                        last_checked_col = 40),
    nest_import(year_1 = "2018", year_2 = "2019", 
                        file_name = "FP Nesting summary_All years_30062025.xlsx", site = "FP", 
                        first_found_date_col = 12, 
                        last_alive_date_col = 33, 
                        last_checked_col = 40),
    nest_import(year_1 = "2017", year_2 = "2018",
                        file_name = "FP Nesting summary_All years_30062025.xlsx", site = "FP", 
                        first_found_date_col = 12, 
                        last_alive_date_col = 33, 
                        last_checked_col = 40),
    nest_import(year_1 = "2016", year_2 = "2017",
                        file_name = "FP Nesting summary_All years_30062025.xlsx", site = "FP", 
                        first_found_date_col = 12, 
                        last_alive_date_col = 33, 
                        last_checked_col = 40),
    nest_import(year_1 = "2015", year_2 = "2016",
                        file_name = "FP Nesting summary_All years_30062025.xlsx", site = "FP", 
                        first_found_date_col = 12, 
                        last_alive_date_col = 33, 
                        last_checked_col = 40),
    nest_import(year_1 = "2014", year_2 = "2015",
                        file_name = "FP Nesting summary_All years_30062025.xlsx", site = "FP", 
                        first_found_date_col = 12, 
                        last_alive_date_col = 33, 
                        last_checked_col = 40),
    nest_import(year_1 = "2013", year_2 = "2014",
                        file_name = "FP Nesting summary_All years_30062025.xlsx", site = "FP", 
                        first_found_date_col = 12, 
                        last_alive_date_col = 33, 
                        last_checked_col = 40),
    nest_import(year_1 = "2012", year_2 = "2013",
                        file_name = "FP Nesting summary_All years_30062025.xlsx", site = "FP", 
                        first_found_date_col = 12, 
                        last_alive_date_col = 33, 
                        last_checked_col = 40),
    nest_import(year_1 = "2011", year_2 = "2012",
                        file_name = "FP Nesting summary_All years_30062025.xlsx", site = "FP", 
                        first_found_date_col = 12, 
                        last_alive_date_col = 33, 
                        last_checked_col = 40),
    nest_import(year_1 = "2010", year_2 = "2011",
                        file_name = "FP Nesting summary_All years_30062025.xlsx", site = "FP", 
                        first_found_date_col = 12, 
                        last_alive_date_col = 33, 
                        last_checked_col = 40),
    nest_import(year_1 = "2009", year_2 = "2010",
                        file_name = "FP Nesting summary_All years_30062025.xlsx", site = "FP", 
                        first_found_date_col = 12, 
                        last_alive_date_col = 33, 
                        last_checked_col = 40)) %>% 
  group_by(season) %>% 
  mutate(nocc = max(max(LastChecked, na.rm = TRUE), max(LastPresent, na.rm = TRUE)),
         season = as.factor(season),
         nest_hab = as.factor(nest_hab),
         management_status = as.factor(management_status)) %>% 
  filter(!is.na(FirstFound) & !is.na(LastPresent) & !is.na(LastChecked)) %>% 
  filter(management_status %in% c("Y", "N")) %>% 
  filter(nest_hab %in% c("beach", "dune", "foredune/face", "estuary/spit", "rocks")) %>%
  filter(!is.na(management_level)) %>% # drops 20 nests
  mutate(region = "FP") %>% 
  mutate(site = as.factor(site)) %>%
  group_by(season, site) %>%
  arrange(first_found2, .by_group = TRUE) %>%
  mutate(rank = row_number()) %>%
  ungroup() %>%
  mutate(nest_ID_new = paste(season, site, rank, sep = "_")) %>% 
  ungroup()

Visual inspections of data

Code
nest_data_FP_check <-
  nest_data_FP %>% 
  ungroup() %>% 
  mutate(first_found2_md = paste(format(first_found2 + 180, format = "%m"),
                                 format(first_found2 + 180, format = "%d"),
                                 sep = "-"),
         last_alive2_md = paste(format(last_alive2 + 180, format = "%m"),
                                format(last_alive2 + 180, format = "%d"),
                                sep = "-"),
         last_checked2_md = paste(format(last_checked2 + 180, format = "%m"),
                                  format(last_checked2 + 180, format = "%d"),
                                  sep = "-")) %>% 
  mutate(first_found2_trans = as.Date(paste("2020", first_found2_md, sep = "-"), format = "%Y-%m-%d") - 179,
         last_alive2_trans = as.Date(paste("2020", last_alive2_md, sep = "-"), format = "%Y-%m-%d") - 179,
         last_checked2_trans = as.Date(paste("2020", last_checked2_md, sep = "-"), format = "%Y-%m-%d") - 179) %>% 
  mutate(season_label = paste0("season ", str_sub(season, 1, 4), " to ", str_sub(season, 5, 6)))
Spatial distribution of data

Note that this map only shows data that are in a decimal degrees format (e.g., -38.31), NOT degree minute seconds (e.g., 38 27.59). The map is interactive, so click on an outlier to see its metadata

Code
nest_data_FP_sf <-
  nest_data_FP %>% 
  as.data.frame() %>% 
  mutate(nest_lon = as.numeric(nest_lon),
         nest_lat = as.numeric(nest_lat)) %>% 
  filter(!is.na(nest_lon) & !is.na(nest_lat)) %>%
  st_as_sf(coords = c("nest_lon", "nest_lat"), 
           crs = 4326) %>% suppressWarnings()

mapview(nest_data_FP_sf,
        zcol = "season", 
        popup = popupTable(nest_data_FP_sf,
                           zcol = c("season",
                                    "site",
                                    "nest_ID")))
Year-specific Found Date Distributions
Code
ggplot(nest_data_FP_check, aes(first_found2_trans, fill = Fate)) +
  geom_histogram(bins = 30,
                 alpha = 0.8, color = "white", linewidth = 0.2) +
  scale_fill_manual(values = c("1" = brewer.pal(8, "Set1")[c(1)], "0" = brewer.pal(8, "Set1")[c(2)]),
                    name = "Nest Fate",
                    labels = c("Hatched", "Failed")) +
  ylab("weekly number of nests") +
  scale_x_date(date_labels = "%B", 
               # expand = c(0.01, 0.01), 
               date_breaks = "1 months", limits = c(min(nest_data_FP_check$first_found2_trans, na.rm = TRUE), 
                                                    max(nest_data_FP_check$last_checked2_trans, na.rm = TRUE))) +
  facet_wrap("season_label") +
  scale_y_continuous(limits = c(0, 12), breaks = c(2, 4, 6, 8, 10)) +
  luke_theme +
  xlab("Found date") +
  theme(legend.position = "top",
        panel.grid.major = element_line(colour = "grey70", 
                                        size = 0.15),
        axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5))

Year-specific Last Alive Date Distributions
Code
ggplot(nest_data_FP_check, aes(last_alive2_trans, fill = as.factor(Fate))) +
  geom_histogram(bins = 30,
                 alpha = 0.8, color = "white", linewidth = 0.2) +
  scale_fill_manual(values = c("1" = brewer.pal(8, "Set1")[c(1)], "0" = brewer.pal(8, "Set1")[c(2)]),
                    name = "Nest Fate",
                    labels = c("Hatched", "Failed")) +
  ylab("weekly number of nests") +
  scale_x_date(date_labels = "%B", 
               expand = c(0.01, 0.01), 
               date_breaks = "1 months", limits = c(min(nest_data_FP_check$first_found2_trans, na.rm = TRUE), 
                                                    max(nest_data_FP_check$last_checked2_trans, na.rm = TRUE))) +
  facet_wrap("season_label") +
  scale_y_continuous(limits = c(0, 12), breaks = c(2, 4, 6, 8, 10, 12)) +
  luke_theme +
  xlab("Last alive date") +
  theme(legend.position = "top",
        panel.grid.major = element_line(colour = "grey70", 
                                        size = 0.15),
        axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5))

Year-specific Last Checked Date Distributions
Code
ggplot(nest_data_FP_check, aes(last_checked2_trans, fill = as.factor(Fate))) +
  geom_histogram(bins = 30,
                 alpha = 0.8, color = "white", linewidth = 0.2) +
  scale_fill_manual(values = c("1" = brewer.pal(8, "Set1")[c(1)], "0" = brewer.pal(8, "Set1")[c(2)]),
                    name = "Nest Fate",
                    labels = c("Hatched", "Failed")) +
  ylab("weekly number of nests") +
  scale_x_date(date_labels = "%B",
               expand = c(0.01, 0.01),
               date_breaks = "1 months", limits = c(min(nest_data_FP_check$first_found2_trans, na.rm = TRUE),
                                                    max(nest_data_FP_check$last_checked2_trans, na.rm = TRUE))) +
  facet_wrap("season_label") +
  scale_y_continuous(limits = c(0, 12), breaks = c(2, 4, 6, 8, 10, 12)) +
  luke_theme +
  xlab("Last checked date") +
  theme(legend.position = "top",
        panel.grid.major = element_line(colour = "grey70", 
                                        size = 0.15),
        axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5))

Tally number of nests per year in the dataset
Code
nest_data_FP_check %>% 
  group_by(season) %>% 
  summarise(n())
# A tibble: 15 × 2
   season `n()`
   <fct>  <int>
 1 200910     8
 2 201011    22
 3 201112    14
 4 201213    21
 5 201314    25
 6 201415    29
 7 201516    35
 8 201617    50
 9 201718    49
10 201819    70
11 201920    73
12 202021    94
13 202122    90
14 202223    82
15 202324   113
Code
nest_data_FP_check %>% 
  summarise(n())
# A tibble: 1 × 1
  `n()`
  <int>
1   775
Incubation length distribution
Code
# assess if there are nests with unusually long incubation periods
nest_data_FP_check %>% 
  mutate(found_and_alive_diff = last_alive2 - first_found2) %>%
  arrange(desc(found_and_alive_diff)) %>% 
  filter(first_found2 < last_alive2 & first_found2 < last_checked2 & found_and_alive_diff < 100) %>% 
  ggplot() +
  geom_histogram(aes(found_and_alive_diff)) +
  luke_theme +
  xlab("Time between found date and last alive date (days)") +
  ylab("Frquency of nests")

# A tibble: 0 × 33
# ℹ 33 variables: season <fct>, site <fct>, nest_ID <chr>, first_found <chr>,
#   last_alive <chr>, last_checked <chr>, Fate <chr>, nest_hab <fct>,
#   management_status <fct>, management_type <chr>, nest_lat <chr>,
#   nest_lon <chr>, chick_1st_ob <date>, clutch_comp <date>,
#   state_1st_ob <chr>, last_alive2 <date>, first_found2 <date>,
#   last_checked2 <date>, FirstFound <dbl>, LastPresent <dbl>,
#   LastChecked <dbl>, sign_access <dbl>, perm_fence <dbl>, sign_nest <dbl>, …
# A tibble: 0 × 33
# ℹ 33 variables: season <fct>, site <fct>, nest_ID <chr>, first_found <chr>,
#   last_alive <chr>, last_checked <chr>, Fate <chr>, nest_hab <fct>,
#   management_status <fct>, management_type <chr>, nest_lat <chr>,
#   nest_lon <chr>, chick_1st_ob <date>, clutch_comp <date>,
#   state_1st_ob <chr>, last_alive2 <date>, first_found2 <date>,
#   last_checked2 <date>, FirstFound <dbl>, LastPresent <dbl>,
#   LastChecked <dbl>, sign_access <dbl>, perm_fence <dbl>, sign_nest <dbl>, …
# A tibble: 0 × 33
# ℹ 33 variables: season <fct>, site <fct>, nest_ID <chr>, first_found <chr>,
#   last_alive <chr>, last_checked <chr>, Fate <chr>, nest_hab <fct>,
#   management_status <fct>, management_type <chr>, nest_lat <chr>,
#   nest_lon <chr>, chick_1st_ob <date>, clutch_comp <date>,
#   state_1st_ob <chr>, last_alive2 <date>, first_found2 <date>,
#   last_checked2 <date>, FirstFound <dbl>, LastPresent <dbl>,
#   LastChecked <dbl>, sign_access <dbl>, perm_fence <dbl>, sign_nest <dbl>, …
.
Double check dates because incubation time greater than 42 days;  
                                                                1 
# A tibble: 1 × 4
  issues                                     season nest_ID found_and_alive_diff
  <chr>                                      <fct>  <chr>   <drtn>              
1 "Double check dates because incubation ti… 201516 201516… 51 days             

Bellarine / Surf Coast

Flag potential issues in data

As above, first we import the data and run a few checks to assess if there are any rows with the issues listed above

Code
BSC_nest_data_issues <- 
suppressMessages(
  bind_rows(
  read_excel(paste0("data/", "BSC Nesting Summaries_All years_17062025.xlsx"), 
             sheet = paste0("BSC", " ", "2023", "_", str_sub("2024", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "BSC Nesting Summaries_All years_17062025.xlsx"), 
             sheet = paste0("BSC", " ", "2022", "_", str_sub("2023", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "BSC Nesting Summaries_All years_17062025.xlsx"), 
             sheet = paste0("BSC", " ", "2021", "_", str_sub("2022", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "BSC Nesting Summaries_All years_17062025.xlsx"), 
             sheet = paste0("BSC", " ", "2020", "_", str_sub("2021", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "BSC Nesting Summaries_All years_17062025.xlsx"), 
             sheet = paste0("BSC", " ", "2019", "_", str_sub("2020", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "BSC Nesting Summaries_All years_17062025.xlsx"), 
             sheet = paste0("BSC", " ", "2018", "_", str_sub("2019", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "BSC Nesting Summaries_All years_17062025.xlsx"), 
             sheet = paste0("BSC", " ", "2017", "_", str_sub("2018", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "BSC Nesting Summaries_All years_17062025.xlsx"), 
             sheet = paste0("BSC", " ", "2016", "_", str_sub("2017", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "BSC Nesting Summaries_All years_17062025.xlsx"), 
             sheet = paste0("BSC", " ", "2015", "_", str_sub("2016", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "BSC Nesting Summaries_All years_17062025.xlsx"), 
             sheet = paste0("BSC", " ", "2014", "_", str_sub("2015", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "BSC Nesting Summaries_All years_17062025.xlsx"), 
             sheet = paste0("BSC", " ", "2013", "_", str_sub("2014", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "BSC Nesting Summaries_All years_17062025.xlsx"), 
             sheet = paste0("BSC", " ", "2012", "_", str_sub("2013", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "BSC Nesting Summaries_All years_17062025.xlsx"), 
             sheet = paste0("BSC", " ", "2011", "_", str_sub("2012", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "BSC Nesting Summaries_All years_17062025.xlsx"), 
             sheet = paste0("BSC", " ", "2010", "_", str_sub("2011", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "BSC Nesting Summaries_All years_17062025.xlsx"), 
             sheet = paste0("BSC", " ", "2009", "_", str_sub("2010", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "BSC Nesting Summaries_All years_17062025.xlsx"), 
             sheet = paste0("BSC", " ", "2008", "_", str_sub("2009", 3, 4)), 
             col_types = "text", na = "n/a"),
  read_excel(paste0("data/", "BSC Nesting Summaries_All years_17062025.xlsx"), 
             sheet = paste0("BSC", " ", "2007", "_", str_sub("2008", 3, 4)), 
             col_types = "text", na = "n/a"), 
  read_excel(paste0("data/", "BSC Nesting Summaries_All years_17062025.xlsx"), 
             sheet = paste0("BSC", " ", "2006", "_", str_sub("2007", 3, 4)), 
             col_types = "text", na = "n/a"))) %>% 
    filter(!is.na(Season)) %>% 
  rename(first_found = 13,
         last_alive = 33,
         last_checked = 39,
         Fate = `Hatch?`,
         season = Season,
         # site = Site,
         site = `Suggested update to site name`,
         nest_ID = `Nest ID`,
         nest_hab = `Nest habitat`,
         management_status = `Nest managed?`,
         management_type = `Management type`,
         nest_lat = `Nest latitude`,
         nest_lon = `Nest longitude`,
         state_1st_ob = `Age stage first observed`) %>% 
  rename(
    chick_1st_ob = !!names(.)[which(names(.) %in% c("Date chicks sighted", "Chicks first obsv date"))][1],
    clutch_comp  = !!names(.)[which(names(.) %in% c("Known clutch complete date", "Known laying date"))][1]
  ) %>% 
  # chick_1st_ob = which(names(.) %in% c("Date chicks sighted", "Chicks first obsv date"))[1],
  # clutch_comp = which(names(.) %in% c("Known clutch complete date", "Known laying date"))) %>% 
  dplyr::select(season, site, nest_ID, first_found, last_alive, last_checked, Fate, nest_hab, 
                management_status, management_type, nest_lat, nest_lon, site,
                chick_1st_ob, clutch_comp, state_1st_ob) %>%
  mutate(Fate = ifelse(Fate == "?", "Unk", Fate)) %>% 
  mutate(Fate = toupper(Fate)) %>% 
  filter(
    is.na(first_found) | 
      grepl("^\\s*-?\\d+(\\.\\d+)?\\s*$", first_found)
  ) %>%
  mutate(last_checked = ifelse(!is.na(last_checked) & !grepl("^\\s*-?\\d+(\\.\\d+)?\\s*$", last_checked), 
                               NA, last_checked)) %>% 
  mutate(last_alive = ifelse(!is.na(last_alive) & !grepl("^\\s*-?\\d+(\\.\\d+)?\\s*$", last_alive), 
                             NA, last_alive)) %>% 
  mutate(last_alive = ifelse(str_detect(last_alive, "Unk."), NA, last_alive),
         Fate = ifelse(Fate == "Y", 0, 
                       ifelse(Fate == "N", 1, 
                              ifelse(Fate == "UNK", NA, "XXX")))) %>%
  # remove nests without Fate information
  filter(Fate %in% c("0", "1")) %>% 
  mutate(chick_1st_ob = case_when(
    # Excel serial dates stored as numbers
    str_detect(chick_1st_ob, "^[0-9]+$") ~ as.Date(as.numeric(chick_1st_ob), origin = "1899-12-30"),
    
    # Dates with extra text in parentheses — extract only the date part
    str_detect(chick_1st_ob, "^\\d{1,2}/\\d{1,2}/\\d{2,4}") ~ suppressWarnings(
      dmy(str_extract(chick_1st_ob, "^\\d{1,2}/\\d{1,2}/\\d{2,4}"))
    ),
    
    # Everything else (including "Unk", "Failed during laying") → NA
    TRUE ~ as.Date(NA)
  ), 
  clutch_comp =  case_when(
    # Excel serial dates stored as numbers
    str_detect(clutch_comp, "^[0-9]+$") ~ as.Date(as.numeric(clutch_comp), origin = "1899-12-30"),
    
    # Dates with extra text in parentheses — extract only the date part
    str_detect(clutch_comp, "^\\d{1,2}/\\d{1,2}/\\d{2,4}") ~ suppressWarnings(
      dmy(str_extract(clutch_comp, "^\\d{1,2}/\\d{1,2}/\\d{2,4}"))
    ),
    
    # Everything else (including "Unk", "Failed during laying") → NA
    TRUE ~ as.Date(NA)
  )) %>%
  # if the clutch completion date is NA, then estimate it as 35 days before estimated hatch date
  # using the date of first chick observation and the size of the chicks when seen
  mutate(clutch_comp = ifelse(!is.na(clutch_comp), clutch_comp, 
                              ifelse(Fate == 0 & is.na(clutch_comp) & !is.na(chick_1st_ob) & !is.na(state_1st_ob),
                                     ifelse(state_1st_ob == "1/3 adult size, fluffy", chick_1st_ob - 3 - 35,
                                            ifelse(state_1st_ob == "1/2 adult size, fluffy", chick_1st_ob - 10 - 35,
                                                   ifelse(state_1st_ob == "2/3 adult size, fluffy", chick_1st_ob - 19 - 35,
                                                          ifelse(state_1st_ob == "Adult size, mottled grey", chick_1st_ob - 30 - 35,
                                                                 ifelse(state_1st_ob == "Fledged", chick_1st_ob - 35 - 35,
                                                                        ifelse(state_1st_ob == "wet in nest", chick_1st_ob - 35, NA)))))), 
                                     ifelse(Fate == 0 & is.na(clutch_comp) & !is.na(chick_1st_ob) & is.na(state_1st_ob), NA, NA))) %>% as.Date()) %>% 
  mutate(last_alive2 = ifelse(Fate == 0 & !is.na(clutch_comp) & is.na(last_alive), clutch_comp + 35,
                              ifelse(Fate == 0 & is.na(clutch_comp) & !is.na(chick_1st_ob) & !is.na(state_1st_ob) & is.na(last_alive),
                                     ifelse(state_1st_ob == "1/3 adult size, fluffy", chick_1st_ob - 3,
                                            ifelse(state_1st_ob == "1/2 adult size, fluffy", chick_1st_ob - 10,
                                                   ifelse(state_1st_ob == "2/3 adult size, fluffy", chick_1st_ob - 19,
                                                          ifelse(state_1st_ob == "Adult size, mottled grey", chick_1st_ob - 30,
                                                                 ifelse(state_1st_ob == "Fledged", chick_1st_ob - 35,
                                                                        ifelse(state_1st_ob == "wet in nest", chick_1st_ob, NA)))))), 
                                     ifelse(Fate == 0 & is.na(clutch_comp) & !is.na(chick_1st_ob) & is.na(state_1st_ob) & is.na(last_alive), NA, NA))) %>% as.Date()) %>% 
  # mutate(last_alive2 = ifelse(Fate == 0 & !is.na(chick_1st_ob) & last_alive2 > chick_1st_ob, chick_1st_ob, last_alive2) %>% as.Date()) %>% 
  mutate(last_alive = ifelse(!is.na(last_alive2), 
                             paste0(str_sub(as.character(last_alive2), 9, 10),
                                    str_sub(as.character(last_alive2), 6, 7),
                                    str_sub(as.character(last_alive2), 1, 4)), last_alive)) %>% 
  mutate(
    last_checked = ifelse(!is.na(last_alive) & is.na(last_checked),
                          last_alive,
                          ifelse(is.na(last_alive) & is.na(last_checked),
                                 first_found, last_checked))) %>%
  mutate(
    last_alive = ifelse(is.na(last_alive) & Fate == "0" & !is.na(last_checked),
                        last_checked,
                        ifelse(is.na(last_alive) & Fate == "1" & !is.na(last_checked),
                               first_found,
                               last_alive))) %>%
  filter(
    (is.na(last_alive) | nchar(last_alive) == 8) &
      (is.na(first_found) | nchar(first_found) == 8) &
      (is.na(last_checked) | nchar(last_checked) == 8)
  ) %>% 
  mutate(first_found2 = as.Date(paste(str_sub(first_found, 5, 8),
                                      str_sub(first_found, 3, 4),
                                      str_sub(first_found, 1, 2), sep = "-")),
         last_alive2 = as.Date(paste(str_sub(last_alive, 5, 8),
                                     str_sub(last_alive, 3, 4),
                                     str_sub(last_alive, 1, 2), sep = "-")),
         last_checked2 = as.Date(paste(str_sub(last_checked, 5, 8),
                                       str_sub(last_checked, 3, 4),
                                       str_sub(last_checked, 1, 2), sep = "-"))) %>% 
  mutate(last_checked2 = ifelse(!is.na(last_alive2) & !is.na(last_checked2) & last_checked2 < last_alive2, 
                                last_alive2, last_checked2) %>% as.Date()) %>% 
  mutate(first_found2 = ifelse(!is.na(clutch_comp) & ((last_alive2 - first_found2) > 40 | (last_alive2 - first_found2) < 0)
                               & ((last_alive2 - clutch_comp) < 40 | (last_alive2 - clutch_comp) > 0), 
                               clutch_comp, first_found2) %>% as.Date()) %>% 
  mutate(FirstFound = as.numeric(format(first_found2 + 180, "%j")),
         LastPresent = as.numeric(format(last_alive2 + 180, "%j")),
         LastChecked = as.numeric(format(last_checked2 + 180, "%j"))) %>% 
  # mutate(FirstFound = ((as.integer(format(first_found2, "%j")) -
  #                         as.integer(format(as.Date("2001-06-01"), "%j")) + 1) %% 365) %>%
  #          replace(. == 0, 365),#as.numeric(format(first_found2 + 180, "%j")),
  #        LastPresent = ((as.integer(format(last_alive2, "%j")) -
  #                          as.integer(format(as.Date("2001-06-01"), "%j")) + 1) %% 365) %>%
  #          replace(. == 0, 365),#as.numeric(format(last_alive2 + 180, "%j")),
  #        LastChecked = ((as.integer(format(last_checked2, "%j")) -
  #                          as.integer(format(as.Date("2001-06-01"), "%j")) + 1) %% 365) %>%
  #          replace(. == 0, 365)) %>% #as.numeric(format(last_checked2 + 180, "%j"))) %>% 
  mutate(management_type = tolower(management_type)) %>%
  mutate(nest_hab = tolower(nest_hab)) %>%
  mutate(management_type = str_replace(management_type, "acess", "access")) %>%
  mutate(management_type = str_replace(management_type, "and", ",")) %>%
  mutate(management_type = str_replace(management_type, "temporary", "")) %>%
  mutate(management_type = str_replace_all(management_type, " ", "")) %>%
  mutate(management_type = str_replace_all(management_type, "shelters", "")) %>%
  mutate(management_type = str_replace_all(management_type, "banners", "")) %>%
  mutate(management_type = str_replace_all(management_type, ",,", ",")) %>%
  mutate(sign_access = ifelse(str_detect(management_type, "signaccess"), 1, 0)) %>%
  mutate(sign_nest = ifelse(str_detect(management_type, "signnest"), 1, 0)) %>%
  mutate(rope_fence = ifelse(str_detect(management_type, "ropefence"), 1, 0)) %>%
  mutate(perm_fence = ifelse(str_detect(management_type, "permanentfence"), 1, 0)) %>% # & nest_hab == "dune", 1, 0)) %>%
  mutate(wardens = ifelse(str_detect(management_type, "wardens"), 1, 0)) %>% 
  mutate(none = ifelse(str_detect(management_type, "none"), 1, 
                       ifelse(is.na(management_type) & management_status == "N", 1, 0))) %>%
  mutate(other = ifelse(str_detect(management_type, "other"), 1, 0)) %>%
  mutate(management_level = ifelse((sign_access == 1 | perm_fence == 1) & sign_nest == 1 & rope_fence == 1 & wardens == 1, 4,
                                   ifelse(rope_fence == 1, 3,
                                          ifelse(sign_nest == 1, 2,
                                                 ifelse(sign_access == 1 | perm_fence == 1, 1,
                                                        ifelse(none == 1, 0, NA)))))) %>%
  mutate(sign_nest_no_sign_access = ifelse(sign_access == 0 & sign_nest == 1, 1, 0)) %>%
  mutate(fence_no_sign = ifelse((sign_access == 0 & sign_nest == 0) & rope_fence == 1, 1, 0)) %>%
  mutate(wardens_no_sign = ifelse((sign_access == 0 & sign_nest == 0) & wardens == 1, 1, 0)) %>%
  mutate(wardens_no_fence = ifelse(rope_fence == 1 & wardens == 1, 1, 0)) %>%
  mutate(just_wardens = ifelse(rope_fence == 0 & sign_access == 0 & sign_nest == 0 & wardens == 1, 1, 0)) %>%
  dplyr::select(-other, -sign_nest_no_sign_access, -fence_no_sign, 
                -wardens_no_sign, -wardens_no_fence, -just_wardens) %>%
  group_by(season) %>%
  mutate(nocc = max(max(LastChecked, na.rm = TRUE), max(LastPresent, na.rm = TRUE)),
         season = as.factor(season),
         nest_hab = as.factor(nest_hab),
         management_status = as.factor(management_status)) %>% 
  mutate(region = "MP") %>%
  mutate(site = as.factor(site)) %>%
  mutate(issue1 = ifelse(nchar(first_found) != 8, "found date is not 8 characters; ", NA)) %>% 
  mutate(issue2 = ifelse(nchar(last_alive) != 8, "last seen alive date is not 8 characters; ", NA)) %>% 
  mutate(issue3 = ifelse(nchar(last_checked) != 8, "last checked date is not 8 characters; ", NA)) %>% 
  mutate(issue4 = ifelse(is.na(first_found), "found date missing; ", NA)) %>% 
  mutate(issue5 = ifelse(is.na(last_alive), "last seen alive date missing; ", NA)) %>% 
  mutate(issue6 = ifelse(is.na(last_checked), "last checked date missing; ", NA)) %>% 
  mutate(issue7 = ifelse(management_status %!in% c("Y", "N"), "Nest managed? is not Y or N; ", NA)) %>% 
  mutate(issue8 = ifelse(nest_hab %!in% c("beach", "dune", "foredune/face", "estuary/spit", "rocks"), 
                         "Nest habitat is not beach, dune, foredune/face, estuary/spit, or rocks; ", NA)) %>% 
  mutate(issue9 = ifelse(is.na(management_level), "Management type is not sufficient for making levels; ", NA)) %>%
  mutate(found_and_alive_diff = last_alive2 - first_found2) %>% 
  mutate(issue10 = ifelse(found_and_alive_diff > 40 , "Double check dates because incubation time greater than 40 days; ", NA)) %>% 
  mutate(issue11 = ifelse(first_found2 > last_alive2, "Found date is after Last Alive date (should be greater or equal); ", NA)) %>% 
  mutate(issue12 = ifelse(first_found2 > last_checked2, "Found date is after Last Checked date (should be greater or equal); ", NA)) %>%
  mutate(issue13 = ifelse(last_checked2 < last_alive2, "Last Checked date is before Last Alive date (should be greater or equal); ", NA)) %>% 
  mutate(issues = ifelse(is.na(issue1) & is.na(issue2) & is.na(issue3) & 
                           is.na(issue4) & is.na(issue5) & is.na(issue6) & 
                           is.na(issue7) & is.na(issue8) & is.na(issue9) & 
                           is.na(issue10) & is.na(issue11) & is.na(issue12) & is.na(issue13), NA, 
                         paste0(issue1, issue2, issue3, 
                                issue4, issue5, issue6, 
                                issue7, issue8, issue9,
                                issue10, issue11, issue12, issue13))) %>% 
  mutate(issues = str_remove_all(issues, "NA")) %>% 
  mutate(issues = ifelse(is.na(issues), "usable", issues)) %>% 
  dplyr::select(-issue1, -issue2, -issue3, 
                -issue4, -issue5, -issue6, 
                -issue7, -issue8, -issue9, 
                -issue10, -issue11, -issue12, -issue13) %>% 
  filter(issues != "usable") %>%
  arrange(issues)

all issues (probably most of these can’t be resolved)

Code
# Create a new workbook to store issues as two sheets
BSC_nest_issues <- createWorkbook()

# Add all_issues sheet
addWorksheet(BSC_nest_issues, "all_issues")

# view issues interactively in RStudio Viewer
BSC_nest_data_issues %>%
  datatable(class = 'cell-border stripe', rownames = FALSE, filter = 'top')
Code
# write BSC_nest_data_check
writeData(BSC_nest_issues, sheet = "all_issues", BSC_nest_data_issues)

date-specific issues (probably most of these CAN be resolved)

Code
# Add date_issues
addWorksheet(BSC_nest_issues, "date_issues")

# there are some blank (but non-NA) observations of management_type
BSC_nest_data_issues %>% filter(is.na(management_type))
# A tibble: 0 × 32
# Groups:   season [0]
# ℹ 32 variables: season <fct>, site <fct>, nest_ID <chr>, first_found <chr>,
#   last_alive <chr>, last_checked <chr>, Fate <chr>, nest_hab <fct>,
#   management_status <fct>, management_type <chr>, nest_lat <chr>,
#   nest_lon <chr>, chick_1st_ob <date>, clutch_comp <date>,
#   state_1st_ob <chr>, last_alive2 <date>, first_found2 <date>,
#   last_checked2 <date>, FirstFound <dbl>, LastPresent <dbl>,
#   LastChecked <dbl>, sign_access <dbl>, sign_nest <dbl>, rope_fence <dbl>, …
Code
# view issues interactively in RStudio Viewer
BSC_nest_data_issues %>% 
  filter(first_found != "Not found" & last_alive != "Not seen" & last_checked != "Not seen" & last_checked != "Not revisited") %>%
  filter(str_detect(issues, "date")) %>%
  mutate(issues = str_remove_all(issues, "Management type is not sufficient for making levels; ")) %>%
  mutate(issues = str_remove_all(issues, "Nest habitat is not beach, dune, foredune/face, estuary/spit, or rocks; ")) %>%
  dplyr::select(season, nest_ID, nest_hab, first_found, first_found2, last_alive, last_alive2, last_checked, last_checked2, 
                Fate, found_and_alive_diff, issues)  %>%
  datatable(class = 'cell-border stripe', rownames = FALSE, filter = 'top')
Code
# write BSC_nest_data_check
BSC_nest_data_issues %>% 
  filter(first_found != "Not found" & last_alive != "Not seen" & last_checked != "Not seen" & last_checked != "Not revisited") %>%
  filter(str_detect(issues, "date")) %>%
  mutate(issues = str_remove_all(issues, "Management type is not sufficient for making levels; ")) %>%
  mutate(issues = str_remove_all(issues, "Nest habitat is not Beach, Dune, Foredune/face, Estuary/spit, or Rocks; ")) %>%
  dplyr::select(season, nest_ID, first_found, first_found2, last_alive, last_alive2, last_checked, last_checked2, 
                Fate, found_and_alive_diff, issues) %>% 
  writeData(BSC_nest_issues, sheet = "date_issues", .)

# Save the workbook
saveWorkbook(BSC_nest_issues, here("data/nest_issues_commented/BSC_nest_data_issues_280525.xlsx"), overwrite = TRUE)

Import data

Code
nest_data_BSC <-
  bind_rows(
    nest_import(year_1 = "2023", year_2 = "2024", 
                        file_name = "BSC Nesting Summaries_All years_17062025.xlsx", site = "BSC",
                        first_found_date_col = 13, 
                        last_alive_date_col = 31, 
                        last_checked_col = 37),
    nest_import(year_1 = "2022", year_2 = "2023", 
                        file_name = "BSC Nesting Summaries_All years_17062025.xlsx", site = "BSC",
                        first_found_date_col = 13, 
                        last_alive_date_col = 32, 
                        last_checked_col = 38),
    nest_import(year_1 = "2021", year_2 = "2022", 
                        file_name = "BSC Nesting Summaries_All years_17062025.xlsx", site = "BSC",
                        first_found_date_col = 13, 
                        last_alive_date_col = 31, 
                        last_checked_col = 37),
    nest_import(year_1 = "2020", year_2 = "2021", 
                        file_name = "BSC Nesting Summaries_All years_17062025.xlsx", site = "BSC",
                        first_found_date_col = 12, 
                        last_alive_date_col = 33, 
                        last_checked_col = 40),
    nest_import(year_1 = "2019", year_2 = "2020", 
                        file_name = "BSC Nesting Summaries_All years_17062025.xlsx", site = "BSC",
                        first_found_date_col = 12, 
                        last_alive_date_col = 33, 
                        last_checked_col = 40),
    nest_import(year_1 = "2018", year_2 = "2019", 
                        file_name = "BSC Nesting Summaries_All years_17062025.xlsx", site = "BSC",
                        first_found_date_col = 12, 
                        last_alive_date_col = 33, 
                        last_checked_col = 40),
    nest_import(year_1 = "2017", year_2 = "2018", 
                        file_name = "BSC Nesting Summaries_All years_17062025.xlsx", site = "BSC",
                        first_found_date_col = 12, 
                        last_alive_date_col = 33, 
                        last_checked_col = 40),
    nest_import(year_1 = "2016", year_2 = "2017", 
                        file_name = "BSC Nesting Summaries_All years_17062025.xlsx", site = "BSC",
                        first_found_date_col = 12, 
                        last_alive_date_col = 33, 
                        last_checked_col = 40),
    nest_import(year_1 = "2015", year_2 = "2016", 
                        file_name = "BSC Nesting Summaries_All years_17062025.xlsx", site = "BSC",
                        first_found_date_col = 12, 
                        last_alive_date_col = 33, 
                        last_checked_col = 40),
    nest_import(year_1 = "2014", year_2 = "2015", 
                        file_name = "BSC Nesting Summaries_All years_17062025.xlsx", site = "BSC",
                        first_found_date_col = 12, 
                        last_alive_date_col = 33, 
                        last_checked_col = 40),
    nest_import(year_1 = "2013", year_2 = "2014", 
                        file_name = "BSC Nesting Summaries_All years_17062025.xlsx", site = "BSC",
                        first_found_date_col = 12, 
                        last_alive_date_col = 33, 
                        last_checked_col = 40),
    nest_import(year_1 = "2012", year_2 = "2013", 
                        file_name = "BSC Nesting Summaries_All years_17062025.xlsx", site = "BSC",
                        first_found_date_col = 12, 
                        last_alive_date_col = 33, 
                        last_checked_col = 40),
    nest_import(year_1 = "2011", year_2 = "2012", 
                        file_name = "BSC Nesting Summaries_All years_17062025.xlsx", site = "BSC",
                        first_found_date_col = 12, 
                        last_alive_date_col = 33, 
                        last_checked_col = 40),
    nest_import(year_1 = "2010", year_2 = "2011", 
                        file_name = "BSC Nesting Summaries_All years_17062025.xlsx", site = "BSC",
                        first_found_date_col = 12, 
                        last_alive_date_col = 33, 
                        last_checked_col = 40),
    nest_import(year_1 = "2009", year_2 = "2010", 
                        file_name = "BSC Nesting Summaries_All years_17062025.xlsx", site = "BSC",
                        first_found_date_col = 12, 
                        last_alive_date_col = 33, 
                        last_checked_col = 40),
    nest_import(year_1 = "2008", year_2 = "2009", 
                        file_name = "BSC Nesting Summaries_All years_17062025.xlsx", site = "BSC",
                        first_found_date_col = 12, 
                        last_alive_date_col = 33, 
                        last_checked_col = 40),
    nest_import(year_1 = "2007", year_2 = "2008", 
                        file_name = "BSC Nesting Summaries_All years_17062025.xlsx", site = "BSC",
                        first_found_date_col = 12, 
                        last_alive_date_col = 33, 
                        last_checked_col = 40),
    nest_import(year_1 = "2006", year_2 = "2007", 
                        file_name = "BSC Nesting Summaries_All years_17062025.xlsx", site = "BSC",
                        first_found_date_col = 12, 
                        last_alive_date_col = 33, 
                        last_checked_col = 40)) %>% 
  group_by(season) %>% 
  mutate(nocc = max(max(LastChecked, na.rm = TRUE), max(LastPresent, na.rm = TRUE)),
         season = as.factor(season),
         nest_hab = as.factor(nest_hab),
         management_status = as.factor(management_status)) %>% 
  filter(!is.na(FirstFound) & !is.na(LastPresent) & !is.na(LastChecked)) %>% 
  filter(management_status %in% c("Y", "N")) %>% 
  filter(nest_hab %in% c("beach", "dune", "foredune/face", "estuary/spit", "rocks")) %>%
  filter(!is.na(management_level)) %>% # drops 5 nests that have permanentfence in beach or foredune habitat OR have only a nondogssign
  mutate(region = "BSC") %>% 
  mutate(site = as.factor(site)) %>%
  group_by(season, site) %>%
  arrange(first_found2, .by_group = TRUE) %>%
  mutate(rank = row_number()) %>%
  ungroup() %>%
  mutate(nest_ID_new = paste(season, site, rank, sep = "_")) %>% 
  ungroup()

Visual inspections of data

Code
nest_data_BSC_check <-
  nest_data_BSC %>% 
  ungroup() %>% 
  mutate(first_found2_md = paste(format(first_found2 + 180, format = "%m"),
                                 format(first_found2 + 180, format = "%d"),
                                 sep = "-"),
         last_alive2_md = paste(format(last_alive2 + 180, format = "%m"),
                                format(last_alive2 + 180, format = "%d"),
                                sep = "-"),
         last_checked2_md = paste(format(last_checked2 + 180, format = "%m"),
                                  format(last_checked2 + 180, format = "%d"),
                                  sep = "-")) %>% 
  mutate(first_found2_trans = as.Date(paste("2020", first_found2_md, sep = "-"), format = "%Y-%m-%d") - 179,
         last_alive2_trans = as.Date(paste("2020", last_alive2_md, sep = "-"), format = "%Y-%m-%d") - 179,
         last_checked2_trans = as.Date(paste("2020", last_checked2_md, sep = "-"), format = "%Y-%m-%d") - 179) %>% 
  mutate(season_label = paste0("season ", str_sub(season, 1, 4), " to ", str_sub(season, 5, 6)))
Spatial distribution of data

Note that this map only shows data that are in a decimal degrees format (e.g., -38.31), NOT degree minute seconds (e.g., 38 27.59). The map is interactive, so click on an outlier to see its metadata

Code
nest_data_BSC_sf <-
  nest_data_BSC %>% 
  as.data.frame() %>% 
  mutate(nest_lon = as.numeric(nest_lon),
         nest_lat = as.numeric(nest_lat)) %>% 
  filter(!is.na(nest_lon) & !is.na(nest_lat)) %>%
  st_as_sf(coords = c("nest_lon", "nest_lat"), 
           crs = 4326) %>% suppressWarnings()

mapview(nest_data_BSC_sf,
        zcol = "season", 
        popup = popupTable(nest_data_BSC_sf,
                           zcol = c("season",
                                    "site",
                                    "nest_ID")))
Year-specific Found Date Distributions
Code
ggplot(nest_data_BSC_check, aes(first_found2_trans, fill = Fate)) +
  geom_histogram(bins = 30,
                 alpha = 0.8, color = "white", linewidth = 0.2) +
  scale_fill_manual(values = c("1" = brewer.pal(8, "Set1")[c(1)], "0" = brewer.pal(8, "Set1")[c(2)]),
                    name = "Nest Fate",
                    labels = c("Hatched", "Failed")) +
  ylab("weekly number of nests") +
  scale_x_date(date_labels = "%B", 
               # expand = c(0.01, 0.01), 
               date_breaks = "1 months", limits = c(min(nest_data_BSC_check$first_found2_trans, na.rm = TRUE), 
                                                    max(nest_data_BSC_check$last_checked2_trans, na.rm = TRUE))) +
  facet_wrap("season_label") +
  scale_y_continuous(limits = c(0, 12), breaks = c(2, 4, 6, 8, 10)) +
  luke_theme +
  xlab("Found date") +
  theme(legend.position = "top",
        panel.grid.major = element_line(colour = "grey70", 
                                        size = 0.15),
        axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5))

Year-specific Last Alive Date Distributions
Code
ggplot(nest_data_BSC_check, aes(last_alive2_trans, fill = as.factor(Fate))) +
  geom_histogram(bins = 30,
                 alpha = 0.8, color = "white", linewidth = 0.2) +
  scale_fill_manual(values = c("1" = brewer.pal(8, "Set1")[c(1)], "0" = brewer.pal(8, "Set1")[c(2)]),
                    name = "Nest Fate",
                    labels = c("Hatched", "Failed")) +
  ylab("weekly number of nests") +
  scale_x_date(date_labels = "%B", 
               expand = c(0.01, 0.01), 
               date_breaks = "1 months", limits = c(min(nest_data_BSC_check$first_found2_trans, na.rm = TRUE), 
                                                    max(nest_data_BSC_check$last_checked2_trans, na.rm = TRUE))) +
  facet_wrap("season_label") +
  scale_y_continuous(limits = c(0, 12), breaks = c(2, 4, 6, 8, 10, 12)) +
  luke_theme +
  xlab("Last alive date") +
  theme(legend.position = "top",
        panel.grid.major = element_line(colour = "grey70", 
                                        size = 0.15),
        axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5))

Year-specific Last Checked Date Distributions
Code
ggplot(nest_data_BSC_check, aes(last_checked2_trans, fill = as.factor(Fate))) +
  geom_histogram(bins = 30,
                 alpha = 0.8, color = "white", linewidth = 0.2) +
  scale_fill_manual(values = c("1" = brewer.pal(8, "Set1")[c(1)], "0" = brewer.pal(8, "Set1")[c(2)]),
                    name = "Nest Fate",
                    labels = c("Hatched", "Failed")) +
  ylab("weekly number of nests") +
  scale_x_date(date_labels = "%B",
               expand = c(0.01, 0.01),
               date_breaks = "1 months", limits = c(min(nest_data_BSC_check$first_found2_trans, na.rm = TRUE),
                                                    max(nest_data_BSC_check$last_checked2_trans, na.rm = TRUE))) +
  facet_wrap("season_label") +
  scale_y_continuous(limits = c(0, 12), breaks = c(2, 4, 6, 8, 10, 12)) +
  luke_theme +
  xlab("Last checked date") +
  theme(legend.position = "top",
        panel.grid.major = element_line(colour = "grey70", 
                                        size = 0.15),
        axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5))

Tally number of nests per year in the dataset
Code
nest_data_BSC_check %>% 
  group_by(season) %>% 
  summarise(n())
# A tibble: 18 × 2
   season `n()`
   <fct>  <int>
 1 200607    13
 2 200708    15
 3 200809    13
 4 200910    17
 5 201011    21
 6 201112    30
 7 201213    26
 8 201314    22
 9 201415    32
10 201516    34
11 201617    45
12 201718    40
13 201819    35
14 201920    42
15 202021    53
16 202122    46
17 202223    44
18 202324    49
Code
nest_data_BSC_check %>% 
  summarise(n())
# A tibble: 1 × 1
  `n()`
  <int>
1   577
Incubation length distribution
Code
# assess if there are nests with unusually long incubation periods
nest_data_BSC_check %>% 
  mutate(found_and_alive_diff = last_alive2 - first_found2) %>%
  arrange(desc(found_and_alive_diff)) %>% 
  filter(first_found2 < last_alive2 & first_found2 < last_checked2 & found_and_alive_diff < 100) %>% 
  ggplot() +
  geom_histogram(aes(found_and_alive_diff)) +
  luke_theme +
  xlab("Time between found date and last alive date (days)") +
  ylab("Frquency of nests")

# A tibble: 0 × 33
# ℹ 33 variables: season <fct>, site <fct>, nest_ID <chr>, first_found <chr>,
#   last_alive <chr>, last_checked <chr>, Fate <chr>, nest_hab <fct>,
#   management_status <fct>, management_type <chr>, nest_lat <chr>,
#   nest_lon <chr>, chick_1st_ob <date>, clutch_comp <date>,
#   state_1st_ob <chr>, last_alive2 <date>, first_found2 <date>,
#   last_checked2 <date>, FirstFound <dbl>, LastPresent <dbl>,
#   LastChecked <dbl>, sign_access <dbl>, perm_fence <dbl>, sign_nest <dbl>, …
# A tibble: 0 × 33
# ℹ 33 variables: season <fct>, site <fct>, nest_ID <chr>, first_found <chr>,
#   last_alive <chr>, last_checked <chr>, Fate <chr>, nest_hab <fct>,
#   management_status <fct>, management_type <chr>, nest_lat <chr>,
#   nest_lon <chr>, chick_1st_ob <date>, clutch_comp <date>,
#   state_1st_ob <chr>, last_alive2 <date>, first_found2 <date>,
#   last_checked2 <date>, FirstFound <dbl>, LastPresent <dbl>,
#   LastChecked <dbl>, sign_access <dbl>, perm_fence <dbl>, sign_nest <dbl>, …
# A tibble: 1 × 33
  season site         nest_ID first_found last_alive last_checked Fate  nest_hab
  <fct>  <fct>        <chr>   <chr>       <chr>      <chr>        <chr> <fct>   
1 202122 Point Lonsd… 202122… 18112021    08112021   20112021     1     beach   
# ℹ 25 more variables: management_status <fct>, management_type <chr>,
#   nest_lat <chr>, nest_lon <chr>, chick_1st_ob <date>, clutch_comp <date>,
#   state_1st_ob <chr>, last_alive2 <date>, first_found2 <date>,
#   last_checked2 <date>, FirstFound <dbl>, LastPresent <dbl>,
#   LastChecked <dbl>, sign_access <dbl>, perm_fence <dbl>, sign_nest <dbl>,
#   rope_fence <dbl>, wardens <dbl>, none <dbl>, other <dbl>,
#   management_level <dbl>, nocc <dbl>, region <chr>, rank <int>, …
.
                                                                     Double check dates because incubation time greater than 41 days;  
                                                                                                                                     3 
                                                                    Found date is after Last Alive date (should be greater or equal);  
                                                                                                                                     3 
Found date is after Last Alive date (should be greater or equal); Found date is after Last Checked date (should be greater or equal);  
                                                                                                                                     1 
# A tibble: 7 × 3
  issues                                                            season site 
  <chr>                                                             <fct>  <fct>
1 "Double check dates because incubation time greater than 41 days… 200708 Poin…
2 "Double check dates because incubation time greater than 41 days… 201213 8W O…
3 "Double check dates because incubation time greater than 41 days… 201617 16W-…
4 "Found date is after Last Alive date (should be greater or equal… 201112 13th…
5 "Found date is after Last Alive date (should be greater or equal… 201213 13th…
6 "Found date is after Last Alive date (should be greater or equal… 202122 Poin…
7 "Found date is after Last Alive date (should be greater or equal… 200708 50W …

Importing and checking threat data

Code
MP_threat_data <- 
  read_excel("data/Threat data all years 25062025.xlsx",
             sheet = "MP threats (all years)", 
             col_types = "text") %>% 
  mutate(season = str_remove(Season, "/")) %>%
  rename(obs_lon = `Observation Longitude`,
         obs_lat = `Observation Latitude`,
         obs_date = `Observation Date`) %>% 
  mutate(obs_date = as.Date(as.numeric(obs_date), 
                            origin = "1899-12-30")) %>% 
  mutate(obs_date2 = as.numeric(format(obs_date + 180, "%j"))) %>% 
  mutate(region = "MP")

FP_threat_data <- 
  read_excel("data/Threat data all years 25062025.xlsx",
             sheet = "FP threat (all years)", 
             col_types = "text") %>% 
  mutate(season = str_remove(Season, "/")) %>%
  rename(obs_lon = `Observation Longitude`,
         obs_lat = `Observation Latitude`,
         obs_date = `Observation Date`) %>% 
  mutate(obs_date = as.Date(as.numeric(obs_date), 
                            origin = "1899-12-30")) %>% 
  mutate(obs_date2 = as.numeric(format(obs_date + 180, "%j"))) %>% 
  mutate(region = "FP")

BSC_threat_data <- 
  read_excel("data/Threat data all years 25062025.xlsx",
             sheet = "BSC threats (all years)", 
             col_types = "text") %>% 
  mutate(season = str_remove(Season, "/")) %>%
  rename(obs_lon = `Observation Longitude`,
         obs_lat = `Observation Latitude`,
         obs_date = `Observation date`) %>% 
  mutate(obs_date = as.Date(as.numeric(obs_date), 
                            origin = "1899-12-30")) %>% 
  mutate(obs_date2 = as.numeric(format(obs_date + 180, "%j"))) %>% 
  mutate(region = "BSC")

threat_data <- 
  bind_rows(FP_threat_data, MP_threat_data, BSC_threat_data)
Code
threat_data_ <-
  threat_data %>% 
  rename(site = `Site name`) %>% 
  # first convert all the count columns to numeric
  mutate_at(vars(
    `Walkers/Joggers (wet sand)`,`Walkers/Joggers (dry sand)`,
    `Walkers/Joggers (signs/fence)`,`Walkers/Joggers (Dune)`,`People sunbaking/sitting (wet sand)`,
    `People sunbaking/sitting (dry sand)`,`People sunbaking/sitting (signs/fence)`,
    `People sunbaking/sitting (Dune)`,`Surfers/Swimmers (wet sand)`,
    `Surfers/Swimmers (dry sand)`,`Surfers/Swimmers (signs/fence)`,
    `Surfers/Swimmers (Dune)`,`People Fishing (wet sand)`,
    `People Fishing (dry sand)`,`People Fishing (signs/fence)`,
    `People Fishing (Dune)`,`People Playing Games (wet sand)`,
    `People Playing Games (dry sand)`,`People Playing Games (signs/fence)`,
    `People Playing Games (Dune)`,`Dog Walkers (wet sand)`,
    `Dog Walkers (dry sand)`,`Dog Walkers (signs/fence)`,
    `Dog Walkers (Dune)`,`Dog On Leash (# dogs) (wet sand)`,
    `Dog On Leash (# dogs) (dry sand)`,`Dog On Leash (# dogs) (signs/fence)`,
    `Dog On Leash (# dogs) (Dune)`,`Dog Off Leash (# dogs) (wet sand)`,
    `Dog Off Leash (# dogs) (dry sand)`,`Dog Off Leash (# dogs) (signs/fence)`,
    `Dog Off Leash (# dogs) (Dune)`,`Horses (wet sand)`,
    `Horses (dry sand)`,`Horses (signs/fence)`,
    `Horses (Dune)`,`Permitted vehicle (wet sand)`,
    `Permitted vehicle (dry sand)`,`Permitted vehicle (signs/fence)`,
    `Permitted vehicle (Dune)`,`Illegal vehicle (wet sand)`,
    `Illegal vehicle (dry sand)`,`Illegal vehicle (signs/fence)`,
    `Illegal vehicle (Dune)`,`Ravens (wet sand)`,                     
    `Ravens (dry sand)`,`Ravens (signs/fence)`, 
    `Ravens (Dune)`,`Magpies (wet sand)`, 
    `Magpies (dry sand)`,`Magpies (signs/fence)`, 
    `Magpies (Dune)`,`Silver Gulls (wet sand)`,  
    `Silver Gulls (dry sand)`,`Silver Gulls (signs/fence)`,
    `Silver Gulls (Dune)`,`Pacific/Kelp Gulls (wet sand)`,
    `Pacific/Kelp Gulls (dry sand)`,`Pacific/Kelp Gulls (signs/fence)`,
    `Pacific/Kelp Gulls (Dune)`,`Nankeen Kestrels (wet sand)`,
    `Nankeen Kestrels (dry sand)`,`Nankeen Kestrels (signs/fence)`,
    `Nankeen Kestrels (Dune)`,`Other bird of prey (wet sand)`,
    `Other bird of prey (dry sand)`,`Other bird of prey (signs/fence)`,
    `Other bird of prey (Dune)`,
    `Stock (cattle/sheep) (wet sand)`,
    `Stock (cattle/sheep) (dry sand)`,`Stock (cattle/sheep) (signs/fence)`,
    `Stock (cattle/sheep) (Dune)`), as.numeric) %>% 
  ungroup() %>% 
  
  # take the total sum of counts for each threat type (e.g., humans includes
  # Dog Walkers, People Playing Games, People Fishing, Surfers/Swimmers, 
  # People sunbaking/sitting, and Walkers/Joggers)
  mutate(humans = rowSums(dplyr::select(.,`Walkers/Joggers (wet sand)`, 
                                        `Walkers/Joggers (dry sand)`, 
                                        `Walkers/Joggers (signs/fence)`, 
                                        `Walkers/Joggers (Dune)`, 
                                        `People sunbaking/sitting (wet sand)`, 
                                        `People sunbaking/sitting (dry sand)`, 
                                        `People sunbaking/sitting (signs/fence)`, 
                                        `People sunbaking/sitting (Dune)`, 
                                        `Surfers/Swimmers (wet sand)`, 
                                        `Surfers/Swimmers (dry sand)`, 
                                        `Surfers/Swimmers (signs/fence)`, 
                                        `Surfers/Swimmers (Dune)`, 
                                        `People Fishing (wet sand)`, 
                                        `People Fishing (dry sand)`, 
                                        `People Fishing (signs/fence)`, 
                                        `People Fishing (Dune)`, 
                                        `People Playing Games (wet sand)`, 
                                        `People Playing Games (dry sand)`, 
                                        `People Playing Games (signs/fence)`, 
                                        `People Playing Games (Dune)`, 
                                        `Dog Walkers (wet sand)`, 
                                        `Dog Walkers (dry sand)`, 
                                        `Dog Walkers (signs/fence)`, 
                                        `Dog Walkers (Dune)`), na.rm = TRUE),
         # do a micro-habitat specific sum for humans
         humans_wet = rowSums(dplyr::select(.,`Walkers/Joggers (wet sand)`, 
                                            `People sunbaking/sitting (wet sand)`, 
                                            `Surfers/Swimmers (wet sand)`, 
                                            `People Fishing (wet sand)`, 
                                            `People Playing Games (wet sand)`, 
                                            `Dog Walkers (wet sand)`), na.rm = TRUE),
         humans_dry = rowSums(dplyr::select(.,`Walkers/Joggers (dry sand)`, 
                                            `People sunbaking/sitting (dry sand)`, 
                                            `Surfers/Swimmers (dry sand)`, 
                                            `People Fishing (dry sand)`, 
                                            `People Playing Games (dry sand)`, 
                                            `Dog Walkers (dry sand)`), na.rm = TRUE),
         humans_dune = rowSums(dplyr::select(.,`Walkers/Joggers (Dune)`, 
                                             `People sunbaking/sitting (Dune)`, 
                                            `Surfers/Swimmers (Dune)`, 
                                            `People Fishing (Dune)`, 
                                            `People Playing Games (Dune)`, 
                                            `Dog Walkers (Dune)`), na.rm = TRUE),
         humans_SF = rowSums(dplyr::select(.,`Walkers/Joggers (signs/fence)`, 
                                            `People sunbaking/sitting (signs/fence)`, 
                                            `Surfers/Swimmers (signs/fence)`, 
                                            `People Fishing (signs/fence)`, 
                                            `People Playing Games (signs/fence)`, 
                                            `Dog Walkers (signs/fence)`), na.rm = TRUE),
       dogs = rowSums(dplyr::select(., `Dog On Leash (# dogs) (wet sand)`, 
                                    `Dog On Leash (# dogs) (dry sand)`,
                                    `Dog On Leash (# dogs) (signs/fence)`, 
                                    `Dog On Leash (# dogs) (Dune)`, 
                                    `Dog Off Leash (# dogs) (wet sand)`, 
                                    `Dog Off Leash (# dogs) (dry sand)`, 
                                    `Dog Off Leash (# dogs) (signs/fence)`, 
                                    `Dog Off Leash (# dogs) (Dune)`), na.rm = TRUE),
       # specify a dog on leash and a dog of leash summary
       dogs_on = rowSums(dplyr::select(., `Dog On Leash (# dogs) (wet sand)`, 
                                       `Dog On Leash (# dogs) (dry sand)`,
                                       `Dog On Leash (# dogs) (signs/fence)`, 
                                       `Dog On Leash (# dogs) (Dune)`), na.rm = TRUE),
       dogs_off = rowSums(dplyr::select(., `Dog Off Leash (# dogs) (wet sand)`, 
                                        `Dog Off Leash (# dogs) (dry sand)`, 
                                        `Dog Off Leash (# dogs) (signs/fence)`, 
                                        `Dog Off Leash (# dogs) (Dune)`), na.rm = TRUE),
       pred_birds = rowSums(dplyr::select(., `Ravens (wet sand)`, 
                                          `Ravens (dry sand)`, 
                                          `Ravens (signs/fence)`, 
                                          `Ravens (Dune)`, 
                                          `Magpies (wet sand)`, 
                                          `Magpies (dry sand)`, 
                                          `Magpies (signs/fence)`, 
                                          `Magpies (Dune)`#, 
                                          # `Silver Gulls (wet sand)`,
                                          # `Silver Gulls (dry sand)`,
                                          # `Silver Gulls (signs/fence)`,
                                          # `Silver Gulls (Dune)`,
                                          # `Pacific/Kelp Gulls (wet sand)`,
                                          # `Pacific/Kelp Gulls (dry sand)`,
                                          # `Pacific/Kelp Gulls (signs/fence)`,
                                          # `Pacific/Kelp Gulls (Dune)`,
                                          # `Nankeen Kestrels (wet sand)`, 
                                          # `Nankeen Kestrels (dry sand)`, 
                                          # `Nankeen Kestrels (signs/fence)`, 
                                          # `Nankeen Kestrels (Dune)`, 
                                          # `Other bird of prey (wet sand)`, 
                                          # `Other bird of prey (dry sand)`, 
                                          # `Other bird of prey (signs/fence)`, 
                                          # `Other bird of prey (Dune)`
                                          ), na.rm = TRUE),
       gulls = rowSums(dplyr::select(., #`Ravens (wet sand)`, 
                                          # `Ravens (dry sand)`, 
                                          # `Ravens (signs/fence)`, 
                                          # `Ravens (Dune)`, 
                                          # `Magpies (wet sand)`, 
                                          # `Magpies (dry sand)`, 
                                          # `Magpies (signs/fence)`, 
                                          # `Magpies (Dune)` 
                                          `Silver Gulls (wet sand)`,
                                          `Silver Gulls (dry sand)`,
                                          `Silver Gulls (signs/fence)`,
                                          `Silver Gulls (Dune)`,
                                          `Pacific/Kelp Gulls (wet sand)`,
                                          `Pacific/Kelp Gulls (dry sand)`,
                                          `Pacific/Kelp Gulls (signs/fence)`,
                                          `Pacific/Kelp Gulls (Dune)`
                                          # `Nankeen Kestrels (wet sand)`, 
                                          # `Nankeen Kestrels (dry sand)`, 
                                          # `Nankeen Kestrels (signs/fence)`, 
                                          # `Nankeen Kestrels (Dune)`, 
                                          # `Other bird of prey (wet sand)`, 
                                          # `Other bird of prey (dry sand)`, 
                                          # `Other bird of prey (signs/fence)`, 
                                          # `Other bird of prey (Dune)`
                                          ), na.rm = TRUE),
       vehicles = rowSums(dplyr::select(., `Permitted vehicle (wet sand)`, 
                                        `Permitted vehicle (dry sand)`, 
                                        `Permitted vehicle (signs/fence)`, 
                                        `Permitted vehicle (Dune)`, 
                                        `Illegal vehicle (wet sand)`, 
                                        `Illegal vehicle (dry sand)`, 
                                        `Illegal vehicle (signs/fence)`, 
                                        `Illegal vehicle (Dune)`), na.rm = TRUE),
       hoofed_animals = rowSums(dplyr::select(.,`Horses (wet sand)`, 
                                              `Horses (dry sand)`, 
                                              `Horses (signs/fence)`,
                                              `Horses (Dune)`, 
                                              `Stock (cattle/sheep) (wet sand)`, 
                                              `Stock (cattle/sheep) (dry sand)`, 
                                              `Stock (cattle/sheep) (signs/fence)`, 
                                              `Stock (cattle/sheep) (Dune)`), na.rm = TRUE)) %>% 
  # consolidate columns names
  rename(hum_pri_wet = `Human Prints (wet sand)`,
         hum_pri_dry = `Human Prints (dry sand)`,
         hum_pri_dune = `Human Prints (Dune)`,
         hum_pri_SF = `Human Prints (signs/fence)`,
         fox_pri_wet = `Fox Prints (wet sand)`,
         fox_pri_dry = `Fox Prints (dry sand)`,
         fox_pri_dune = `Fox Prints (Dune)`,
         fox_pri_SF = `Fox Prints (signs/fence)`,
         dog_pri_wet = `Dog Prints (wet sand)`,
         dog_pri_dry = `Dog Prints (dry sand)`,
         dog_pri_dune = `Dog Prints (Dune)`,
         dog_pri_SF = `Dog Prints (signs/fence)`,
         vehicle_pri_wet = `Vehicle Tracks (wet sand)`,
         vehicle_pri_dry = `Vehicle Tracks (dry sand)`,
         vehicle_pri_dune = `Vehicle Tracks (Dune)`,
         vehicle_pri_SF = `Vehicle Tracks (signs/fence)`,
         trailbike_pri_wet = `Trail bike tracks (wet sand)`,
         trailbike_pri_dry = `Trail bike tracks (dry sand)`,
         trailbike_pri_dune = `Trail bike tracks (Dune)`,
         trailbike_pri_SF = `Trail bike tracks (signs/fence)`,
         stock_pri_wet = `Stock (wet sand)`,
         stock_pri_dry = `Stock (dry sand)`,
         stock_pri_dune = `Stock (Dune)`,
         stock_pri_SF = `Stock (signs/fence)`,
         horse_pri_wet = `Horses Prints (wet sand)`,
         horse_pri_dry = `Horses Prints (dry sand)`,
         horse_pri_dune = `Horses Prints (Dune)`,
         horse_pri_SF = `Horses Prints (signs/fence)`) %>%
  # specify coordinates as numeric
  mutate(obs_lon = as.numeric(obs_lon),
         obs_lat = as.numeric(obs_lat)) %>% 
  # clean up factor levels (e.g., sometime "Light", sometimes just "L")
  mutate(hum_pri_wet = ifelse(hum_pri_wet %in% c("Light", "Moderate", "Heavy", "L", "M", "H"), 
                              substr(hum_pri_wet, 1, 1), 
                              ifelse(hum_pri_wet == "0", "N",
                                     ifelse(hum_pri_wet == "1", "L",
                                           ifelse(hum_pri_wet == "2", "M",
                                                  ifelse(hum_pri_wet == "3", "H",
                                                         ifelse(hum_pri_wet == "high", "H", NA)))))) %>% as.factor(.) %>% factor(., levels = c("L", "M", "H")),
         hum_pri_dry = ifelse(hum_pri_dry %in% c("Light", "Moderate", "Heavy", "L", "M", "H"), 
                              substr(hum_pri_dry, 1, 1), 
                              ifelse(hum_pri_dry == "0", "N",
                                     ifelse(hum_pri_dry == "1", "L",
                                           ifelse(hum_pri_dry == "2", "M",
                                                  ifelse(hum_pri_dry == "3", "H",
                                                         ifelse(hum_pri_dry == "high", "H", NA)))))) %>% as.factor(.) %>% factor(., levels = c("L", "M", "H")),
         hum_pri_SF =  ifelse(hum_pri_SF %in% c("Light", "Moderate", "Heavy", "L", "M", "H"), 
                              substr(hum_pri_SF, 1, 1), 
                              ifelse(hum_pri_SF == "0", "N",
                                     ifelse(hum_pri_SF == "1", "L",
                                           ifelse(hum_pri_SF == "2", "M",
                                                  ifelse(hum_pri_SF == "3", "H",
                                                         ifelse(hum_pri_SF == "high", "H", NA)))))) %>% as.factor(.) %>% factor(., levels = c("L", "M", "H")),
         hum_pri_dune = ifelse(hum_pri_dune %in% c("Light", "Moderate", "Heavy", "L", "M", "H"), 
                               substr(hum_pri_dune, 1, 1), 
                              ifelse(hum_pri_dune == "0", "N",
                                     ifelse(hum_pri_dune == "1", "L",
                                           ifelse(hum_pri_dune == "2", "M",
                                                  ifelse(hum_pri_dune == "3", "H",
                                                         ifelse(hum_pri_dune == "high", "H", NA)))))) %>% as.factor(.) %>% factor(., levels = c("L", "M", "H")),
         fox_pri_wet = ifelse(fox_pri_wet %in% c("Light", "Moderate", "Heavy", "L", "M", "H"), 
                              substr(fox_pri_wet, 1, 1), 
                              ifelse(fox_pri_wet == "0", "N",
                                     ifelse(fox_pri_wet == "1", "L",
                                           ifelse(fox_pri_wet == "2", "M",
                                                  ifelse(fox_pri_wet == "3", "H",
                                                         ifelse(fox_pri_wet == "high", "H", NA)))))) %>% as.factor(.) %>% factor(., levels = c("L", "M", "H")),
         fox_pri_dry = ifelse(fox_pri_dry %in% c("Light", "Moderate", "Heavy", "L", "M", "H"), 
                              substr(fox_pri_dry, 1, 1), 
                              ifelse(fox_pri_dry == "0", "N",
                                     ifelse(fox_pri_dry == "1", "L",
                                           ifelse(fox_pri_dry == "2", "M",
                                                  ifelse(fox_pri_dry == "3", "H",
                                                         ifelse(fox_pri_dry == "high", "H", NA)))))) %>% as.factor(.) %>% factor(., levels = c("L", "M", "H")),
         fox_pri_SF = ifelse(fox_pri_SF %in% c("Light", "Moderate", "Heavy", "L", "M", "H"), 
                             substr(fox_pri_SF, 1, 1), 
                              ifelse(fox_pri_SF == "0", "N",
                                     ifelse(fox_pri_SF == "1", "L",
                                           ifelse(fox_pri_SF == "2", "M",
                                                  ifelse(fox_pri_SF == "3", "H",
                                                         ifelse(fox_pri_SF == "high", "H", NA)))))) %>% as.factor(.) %>% factor(., levels = c("L", "M", "H")),
         fox_pri_dune = ifelse(fox_pri_dune %in% c("Light", "Moderate", "Heavy", "L", "M", "H"), 
                               substr(fox_pri_dune, 1, 1), 
                              ifelse(fox_pri_dune == "0", "N",
                                     ifelse(fox_pri_dune == "1", "L",
                                           ifelse(fox_pri_dune == "2", "M",
                                                  ifelse(fox_pri_dune == "3", "H",
                                                         ifelse(fox_pri_dune == "high", "H", NA)))))) %>% as.factor(.) %>% factor(., levels = c("L", "M", "H")),
         dog_pri_wet = ifelse(dog_pri_wet %in% c("Light", "Moderate", "Heavy", "L", "M", "H"), 
                              substr(dog_pri_wet, 1, 1), 
                              ifelse(dog_pri_wet == "0", "N",
                                     ifelse(dog_pri_wet == "1", "L",
                                           ifelse(dog_pri_wet == "2", "M",
                                                  ifelse(dog_pri_wet == "3", "H",
                                                         ifelse(dog_pri_wet == "high", "H", NA)))))) %>% as.factor(.) %>% factor(., levels = c("L", "M", "H")),
         dog_pri_dry = ifelse(dog_pri_dry %in% c("Light", "Moderate", "Heavy", "L", "M", "H"), 
                              substr(dog_pri_dry, 1, 1), 
                              ifelse(dog_pri_dry == "0", "N",
                                     ifelse(dog_pri_dry == "1", "L",
                                           ifelse(dog_pri_dry == "2", "M",
                                                  ifelse(dog_pri_dry == "3", "H",
                                                         ifelse(dog_pri_dry == "high", "H", NA)))))) %>% as.factor(.) %>% factor(., levels = c("L", "M", "H")),
         dog_pri_SF = ifelse(dog_pri_SF %in% c("Light", "Moderate", "Heavy", "L", "M", "H"), 
                             substr(dog_pri_SF, 1, 1), 
                              ifelse(dog_pri_SF == "0", "N",
                                     ifelse(dog_pri_SF == "1", "L",
                                           ifelse(dog_pri_SF == "2", "M",
                                                  ifelse(dog_pri_SF == "3", "H",
                                                         ifelse(dog_pri_SF == "high", "H", NA)))))) %>% as.factor(.) %>% factor(., levels = c("L", "M", "H")),
         dog_pri_dune = ifelse(dog_pri_dune %in% c("Light", "Moderate", "Heavy", "L", "M", "H"), 
                               substr(dog_pri_dune, 1, 1), 
                              ifelse(dog_pri_dune == "0", "N",
                                     ifelse(dog_pri_dune == "1", "L",
                                           ifelse(dog_pri_dune == "2", "M",
                                                  ifelse(dog_pri_dune == "3", "H",
                                                         ifelse(dog_pri_dune == "high", "H", NA)))))) %>% as.factor(.) %>% factor(., levels = c("L", "M", "H")),
         vehicle_pri_wet = ifelse(vehicle_pri_wet %in% c("Light", "Moderate", "Heavy", "L", "M", "H"), 
                                  substr(vehicle_pri_wet, 1, 1), 
                              ifelse(vehicle_pri_wet == "0", "N",
                                     ifelse(vehicle_pri_wet == "1", "L",
                                           ifelse(vehicle_pri_wet == "2", "M",
                                                  ifelse(vehicle_pri_wet == "3", "H",
                                                         ifelse(vehicle_pri_wet == "high", "H", NA)))))) %>% as.factor(.) %>% factor(., levels = c("L", "M", "H")),
         vehicle_pri_dry = ifelse(vehicle_pri_dry %in% c("Light", "Moderate", "Heavy", "L", "M", "H"), 
                                  substr(vehicle_pri_dry, 1, 1), 
                              ifelse(vehicle_pri_dry == "0", "N",
                                     ifelse(vehicle_pri_dry == "1", "L",
                                           ifelse(vehicle_pri_dry == "2", "M",
                                                  ifelse(vehicle_pri_dry == "3", "H",
                                                         ifelse(vehicle_pri_dry == "high", "H", NA)))))) %>% as.factor(.) %>% factor(., levels = c("L", "M", "H")),
         vehicle_pri_SF = ifelse(vehicle_pri_SF %in% c("Light", "Moderate", "Heavy", "L", "M", "H"), 
                                 substr(vehicle_pri_SF, 1, 1), 
                              ifelse(vehicle_pri_SF == "0", "N",
                                     ifelse(vehicle_pri_SF == "1", "L",
                                           ifelse(vehicle_pri_SF == "2", "M",
                                                  ifelse(vehicle_pri_SF == "3", "H",
                                                         ifelse(vehicle_pri_SF == "high", "H", NA)))))) %>% as.factor(.) %>% factor(., levels = c("L", "M", "H")),
         vehicle_pri_dune = ifelse(vehicle_pri_dune %in% c("Light", "Moderate", "Heavy", "L", "M", "H"), 
                                   substr(vehicle_pri_dune, 1, 1), 
                              ifelse(vehicle_pri_dune == "0", "N",
                                     ifelse(vehicle_pri_dune == "1", "L",
                                           ifelse(vehicle_pri_dune == "2", "M",
                                                  ifelse(vehicle_pri_dune == "3", "H",
                                                         ifelse(vehicle_pri_dune == "high", "H", NA)))))) %>% as.factor(.) %>% factor(., levels = c("L", "M", "H")),
         trailbike_pri_wet = ifelse(trailbike_pri_wet %in% c("Light", "Moderate", "Heavy", "L", "M", "H"), 
                                    substr(trailbike_pri_wet, 1, 1), 
                              ifelse(trailbike_pri_wet == "0", "N",
                                     ifelse(trailbike_pri_wet == "1", "L",
                                           ifelse(trailbike_pri_wet == "2", "M",
                                                  ifelse(trailbike_pri_wet == "3", "H",
                                                         ifelse(trailbike_pri_wet == "high", "H", NA)))))) %>% as.factor(.) %>% factor(., levels = c("L", "M", "H")),
         trailbike_pri_dry = ifelse(trailbike_pri_dry %in% c("Light", "Moderate", "Heavy", "L", "M", "H"), 
                                    substr(trailbike_pri_dry, 1, 1), 
                              ifelse(trailbike_pri_dry == "0", "N",
                                     ifelse(trailbike_pri_dry == "1", "L",
                                           ifelse(trailbike_pri_dry == "2", "M",
                                                  ifelse(trailbike_pri_dry == "3", "H",
                                                         ifelse(trailbike_pri_dry == "high", "H", NA)))))) %>% as.factor(.) %>% factor(., levels = c("L", "M", "H")),
         trailbike_pri_SF = ifelse(trailbike_pri_SF %in% c("Light", "Moderate", "Heavy", "L", "M", "H"), 
                                   substr(trailbike_pri_SF, 1, 1), 
                              ifelse(trailbike_pri_SF == "0", "N",
                                     ifelse(trailbike_pri_SF == "1", "L",
                                           ifelse(trailbike_pri_SF == "2", "M",
                                                  ifelse(trailbike_pri_SF == "3", "H",
                                                         ifelse(trailbike_pri_SF == "high", "H", NA)))))) %>% as.factor(.) %>% factor(., levels = c("L", "M", "H")),
         trailbike_pri_dune = ifelse(trailbike_pri_dune %in% c("Light", "Moderate", "Heavy", "L", "M", "H"), 
                                     substr(trailbike_pri_dune, 1, 1), 
                              ifelse(trailbike_pri_dune == "0", "N",
                                     ifelse(trailbike_pri_dune == "1", "L",
                                           ifelse(trailbike_pri_dune == "2", "M",
                                                  ifelse(trailbike_pri_dune == "3", "H",
                                                         ifelse(trailbike_pri_dune == "high", "H", NA)))))) %>% as.factor(.) %>% factor(., levels = c("L", "M", "H")),
         horse_pri_wet = ifelse(horse_pri_wet %in% c("Light", "Moderate", "Heavy", "L", "M", "H"), 
                                substr(horse_pri_wet, 1, 1), 
                              ifelse(horse_pri_wet == "0", "N",
                                     ifelse(horse_pri_wet == "1", "L",
                                           ifelse(horse_pri_wet == "2", "M",
                                                  ifelse(horse_pri_wet == "3", "H",
                                                         ifelse(horse_pri_wet == "high", "H", NA)))))) %>% as.factor(.) %>% factor(., levels = c("L", "M", "H")),
         horse_pri_dry = ifelse(horse_pri_dry %in% c("Light", "Moderate", "Heavy", "L", "M", "H"), 
                                substr(horse_pri_dry, 1, 1), 
                              ifelse(horse_pri_dry == "0", "N",
                                     ifelse(horse_pri_dry == "1", "L",
                                           ifelse(horse_pri_dry == "2", "M",
                                                  ifelse(horse_pri_dry == "3", "H",
                                                         ifelse(horse_pri_dry == "high", "H", NA)))))) %>% as.factor(.) %>% factor(., levels = c("L", "M", "H")),
         horse_pri_SF = ifelse(horse_pri_SF %in% c("Light", "Moderate", "Heavy", "L", "M", "H"), 
                               substr(horse_pri_SF, 1, 1), 
                              ifelse(horse_pri_SF == "0", "N",
                                     ifelse(horse_pri_SF == "1", "L",
                                           ifelse(horse_pri_SF == "2", "M",
                                                  ifelse(horse_pri_SF == "3", "H",
                                                         ifelse(horse_pri_SF == "high", "H", NA)))))) %>% as.factor(.) %>% factor(., levels = c("L", "M", "H")),
         horse_pri_dune = ifelse(horse_pri_dune %in% c("Light", "Moderate", "Heavy", "L", "M", "H"), 
                                 substr(horse_pri_dune, 1, 1), 
                              ifelse(horse_pri_dune == "0", "N",
                                     ifelse(horse_pri_dune == "1", "L",
                                           ifelse(horse_pri_dune == "2", "M",
                                                  ifelse(horse_pri_dune == "3", "H",
                                                         ifelse(horse_pri_dune == "high", "H", NA)))))) %>% as.factor(.) %>% factor(., levels = c("L", "M", "H")),
         stock_pri_wet = ifelse(stock_pri_wet %in% c("Light", "Moderate", "Heavy", "L", "M", "H"), 
                                substr(stock_pri_wet, 1, 1), 
                              ifelse(stock_pri_wet == "0", "N",
                                     ifelse(stock_pri_wet == "1", "L",
                                           ifelse(stock_pri_wet == "2", "M",
                                                  ifelse(stock_pri_wet == "3", "H",
                                                         ifelse(stock_pri_wet == "high", "H", NA)))))) %>% as.factor(.) %>% factor(., levels = c("L", "M", "H")),
         stock_pri_dry = ifelse(stock_pri_dry %in% c("Light", "Moderate", "Heavy", "L", "M", "H"), 
                                substr(stock_pri_dry, 1, 1), 
                              ifelse(stock_pri_dry == "0", "N",
                                     ifelse(stock_pri_dry == "1", "L",
                                           ifelse(stock_pri_dry == "2", "M",
                                                  ifelse(stock_pri_dry == "3", "H",
                                                         ifelse(stock_pri_dry == "high", "H", NA)))))) %>% as.factor(.) %>% factor(., levels = c("L", "M", "H")),
         stock_pri_SF = ifelse(stock_pri_SF %in% c("Light", "Moderate", "Heavy", "L", "M", "H"), 
                               substr(stock_pri_SF, 1, 1), 
                              ifelse(stock_pri_SF == "0", "N",
                                     ifelse(stock_pri_SF == "1", "L",
                                           ifelse(stock_pri_SF == "2", "M",
                                                  ifelse(stock_pri_SF == "3", "H",
                                                         ifelse(stock_pri_SF == "high", "H", NA)))))) %>% as.factor(.) %>% factor(., levels = c("L", "M", "H")),
         stock_pri_dune = ifelse(stock_pri_dune %in% c("Light", "Moderate", "Heavy", "L", "M", "H"), 
                                 substr(stock_pri_dune, 1, 1), 
                              ifelse(stock_pri_dune == "0", "N",
                                     ifelse(stock_pri_dune == "1", "L",
                                           ifelse(stock_pri_dune == "2", "M",
                                                  ifelse(stock_pri_dune == "3", "H",
                                                         ifelse(stock_pri_dune == "high", "H", NA)))))) %>% as.factor(.) %>% factor(., levels = c("L", "M", "H"))) %>% 
  # to control for multiple threat surveys per date, summarise by date
  group_by(region, site, season, obs_date, obs_date2) %>% 
  summarise(obs_lon = mean(obs_lon, na.rm = TRUE),
            obs_lat = mean(obs_lat, na.rm = TRUE),
            # in the case of multiple surveys on a single date at a specific 
            # site, take the max humans counted, etc., and the highest level of
            # prints, etc.
            humans = max(humans, na.rm = TRUE),
            humans_wet = max(humans_wet, na.rm = TRUE),
            humans_dry = max(humans_dry, na.rm = TRUE),
            humans_dune = max(humans_dune, na.rm = TRUE),
            humans_SF = max(humans_SF, na.rm = TRUE),
            hoofed_animals = max(hoofed_animals, na.rm = TRUE),
            vehicles = max(vehicles, na.rm = TRUE),
            pred_birds = max(pred_birds, na.rm = TRUE),
            gulls = max(gulls, na.rm = TRUE),
            dogs_off = max(dogs_off, na.rm = TRUE),
            dogs_on = max(dogs_on, na.rm = TRUE),
            dogs = max(dogs, na.rm = TRUE),
            hum_pri_wet = ifelse(all(is.na(hum_pri_wet)), NA, 
                                 levels(hum_pri_wet)[max(as.integer(hum_pri_wet), na.rm = TRUE)]),
            hum_pri_dry = ifelse(all(is.na(hum_pri_dry)), NA, 
                                 levels(hum_pri_dry)[max(as.integer(hum_pri_dry), na.rm = TRUE)]),
            hum_pri_dune = ifelse(all(is.na(hum_pri_dune)), NA, 
                                  levels(hum_pri_dune)[max(as.integer(hum_pri_dune), na.rm = TRUE)]),
            hum_pri_SF = ifelse(all(is.na(hum_pri_SF)), NA, 
                                levels(hum_pri_SF)[max(as.integer(hum_pri_SF), na.rm = TRUE)]),
            fox_pri_wet = ifelse(all(is.na(fox_pri_wet)), NA, 
                                 levels(fox_pri_wet)[max(as.integer(fox_pri_wet), na.rm = TRUE)]),
            fox_pri_dry = ifelse(all(is.na(fox_pri_dry)), NA, 
                                 levels(fox_pri_dry)[max(as.integer(fox_pri_dry), na.rm = TRUE)]),
            fox_pri_dune = ifelse(all(is.na(fox_pri_dune)), NA, 
                                  levels(fox_pri_dune)[max(as.integer(fox_pri_dune), na.rm = TRUE)]),
            fox_pri_SF = ifelse(all(is.na(fox_pri_SF)), NA, 
                                levels(fox_pri_SF)[max(as.integer(fox_pri_SF), na.rm = TRUE)]),
            dog_pri_wet = ifelse(all(is.na(dog_pri_wet)), NA, 
                                 levels(dog_pri_wet)[max(as.integer(dog_pri_wet), na.rm = TRUE)]),
            dog_pri_dry = ifelse(all(is.na(dog_pri_dry)), NA, 
                                 levels(dog_pri_dry)[max(as.integer(dog_pri_dry), na.rm = TRUE)]),
            dog_pri_dune = ifelse(all(is.na(dog_pri_dune)), NA, 
                                  levels(dog_pri_dune)[max(as.integer(dog_pri_dune), na.rm = TRUE)]),
            dog_pri_SF = ifelse(all(is.na(dog_pri_SF)), NA, 
                                levels(dog_pri_SF)[max(as.integer(dog_pri_SF), na.rm = TRUE)]),
            vehicle_pri_wet = ifelse(all(is.na(vehicle_pri_wet)), NA, 
                                     levels(vehicle_pri_wet)[max(as.integer(vehicle_pri_wet), na.rm = TRUE)]),
            vehicle_pri_dry = ifelse(all(is.na(vehicle_pri_dry)), NA, 
                                     levels(vehicle_pri_dry)[max(as.integer(vehicle_pri_dry), na.rm = TRUE)]),
            vehicle_pri_dune = ifelse(all(is.na(vehicle_pri_dune)), NA, 
                                      levels(vehicle_pri_dune)[max(as.integer(vehicle_pri_dune), na.rm = TRUE)]),
            vehicle_pri_SF = ifelse(all(is.na(vehicle_pri_SF)), NA, 
                                    levels(vehicle_pri_SF)[max(as.integer(vehicle_pri_SF), na.rm = TRUE)]),
            trailbike_pri_wet = ifelse(all(is.na(trailbike_pri_wet)), NA, 
                                       levels(trailbike_pri_wet)[max(as.integer(trailbike_pri_wet), na.rm = TRUE)]),
            trailbike_pri_dry = ifelse(all(is.na(trailbike_pri_dry)), NA, 
                                       levels(trailbike_pri_dry)[max(as.integer(trailbike_pri_dry), na.rm = TRUE)]),
            trailbike_pri_dune = ifelse(all(is.na(trailbike_pri_dune)), NA, 
                                        levels(trailbike_pri_dune)[max(as.integer(trailbike_pri_dune), na.rm = TRUE)]),
            trailbike_pri_SF = ifelse(all(is.na(trailbike_pri_SF)), NA, 
                                      levels(trailbike_pri_SF)[max(as.integer(trailbike_pri_SF), na.rm = TRUE)]),
            horse_pri_wet = ifelse(all(is.na(horse_pri_wet)), NA, 
                                   levels(horse_pri_wet)[max(as.integer(horse_pri_wet), na.rm = TRUE)]),
            horse_pri_dry = ifelse(all(is.na(horse_pri_dry)), NA, 
                                   levels(horse_pri_dry)[max(as.integer(horse_pri_dry), na.rm = TRUE)]),
            horse_pri_dune = ifelse(all(is.na(horse_pri_dune)), NA, 
                                    levels(horse_pri_dune)[max(as.integer(horse_pri_dune), na.rm = TRUE)]),
            horse_pri_SF = ifelse(all(is.na(horse_pri_SF)), NA, 
                                  levels(horse_pri_SF)[max(as.integer(horse_pri_SF), na.rm = TRUE)]),
            stock_pri_wet = ifelse(all(is.na(stock_pri_wet)), NA, 
                                   levels(stock_pri_wet)[max(as.integer(stock_pri_wet), na.rm = TRUE)]),
            stock_pri_dry = ifelse(all(is.na(stock_pri_dry)), NA, 
                                   levels(stock_pri_dry)[max(as.integer(stock_pri_dry), na.rm = TRUE)]),
            stock_pri_dune = ifelse(all(is.na(stock_pri_dune)), NA, 
                                    levels(stock_pri_dune)[max(as.integer(stock_pri_dune), na.rm = TRUE)]),
            stock_pri_SF = ifelse(all(is.na(stock_pri_SF)), NA, 
                                  levels(stock_pri_SF)[max(as.integer(stock_pri_SF), na.rm = TRUE)])) %>%
  # make the print variables a factor
  mutate_at(vars(hum_pri_wet, hum_pri_dry, hum_pri_dune, hum_pri_SF,
                 dog_pri_wet, dog_pri_dry, dog_pri_dune, dog_pri_SF,
                 fox_pri_wet, fox_pri_dry, fox_pri_dune, fox_pri_SF,
                 vehicle_pri_wet, vehicle_pri_dry, vehicle_pri_dune, vehicle_pri_SF,
                 trailbike_pri_wet, trailbike_pri_dry, trailbike_pri_dune, trailbike_pri_SF,
                 horse_pri_wet, horse_pri_dry, horse_pri_dune, horse_pri_SF,
                 stock_pri_wet, stock_pri_dry, stock_pri_dune, stock_pri_SF),
            ~ as.factor(.)) %>% 
  # specify the level order of the print variables
  mutate_at(vars(hum_pri_wet, hum_pri_dry, hum_pri_dune, hum_pri_SF,
                 dog_pri_wet, dog_pri_dry, dog_pri_dune, dog_pri_SF,
                 fox_pri_wet, fox_pri_dry, fox_pri_dune, fox_pri_SF,
                 vehicle_pri_wet, vehicle_pri_dry, vehicle_pri_dune, vehicle_pri_SF,
                 trailbike_pri_wet, trailbike_pri_dry, trailbike_pri_dune, trailbike_pri_SF,
                 horse_pri_wet, horse_pri_dry, horse_pri_dune, horse_pri_SF,
                 stock_pri_wet, stock_pri_dry, stock_pri_dune, stock_pri_SF),
            ~ factor(., levels = c("L", "M", "H"))) %>% 
  # summarize the print variables across the wet, dry, dune, and sign/fence micro habitats
  mutate(hum_pri = ifelse(all(is.na(hum_pri_wet)) && all(is.na(hum_pri_dry)) && 
                            all(is.na(hum_pri_dune)) && all(is.na(hum_pri_SF)), NA,
                          pmax(as.integer(hum_pri_wet), as.integer(hum_pri_dry), 
                               as.integer(hum_pri_dune), as.integer(hum_pri_SF), na.rm = TRUE)),
         fox_pri = ifelse(all(is.na(fox_pri_wet)) && all(is.na(fox_pri_dry)) && 
                            all(is.na(fox_pri_dune)) && all(is.na(fox_pri_SF)), NA,
                          pmax(as.integer(fox_pri_wet), as.integer(fox_pri_dry), 
                               as.integer(fox_pri_dune), as.integer(fox_pri_SF), na.rm = TRUE)),
         dog_pri = ifelse(all(is.na(dog_pri_wet)) && all(is.na(dog_pri_dry)) && 
                            all(is.na(dog_pri_dune)) && all(is.na(dog_pri_SF)), NA,
                          pmax(as.integer(dog_pri_wet), as.integer(dog_pri_dry), 
                               as.integer(dog_pri_dune), as.integer(dog_pri_SF), na.rm = TRUE)),
         vehicle_pri = ifelse(all(is.na(vehicle_pri_wet)) && all(is.na(vehicle_pri_dry)) && 
                                all(is.na(vehicle_pri_dune)) && all(is.na(vehicle_pri_SF)) &&
                              all(is.na(trailbike_pri_wet)) && all(is.na(trailbike_pri_dry)) && 
                                all(is.na(trailbike_pri_dune)) && all(is.na(trailbike_pri_SF)), NA,
                              pmax(as.integer(vehicle_pri_wet), as.integer(vehicle_pri_dry), 
                                   as.integer(vehicle_pri_dune), as.integer(vehicle_pri_SF), 
                                   as.integer(trailbike_pri_wet), as.integer(trailbike_pri_dry), 
                                   as.integer(trailbike_pri_dune), as.integer(trailbike_pri_SF), na.rm = TRUE)),
         hoofed_pri = ifelse(all(is.na(horse_pri_wet)) && all(is.na(horse_pri_dry)) && 
                               all(is.na(horse_pri_dune)) && all(is.na(horse_pri_SF)) &&
                             all(is.na(stock_pri_wet)) && all(is.na(stock_pri_dry)) && 
                               all(is.na(stock_pri_dune)) && all(is.na(stock_pri_SF)), NA,
                             pmax(as.integer(horse_pri_wet), as.integer(horse_pri_dry), 
                                  as.integer(horse_pri_dune), as.integer(horse_pri_SF), 
                                  as.integer(stock_pri_wet), as.integer(stock_pri_dry), 
                                  as.integer(stock_pri_dune), as.integer(stock_pri_SF), na.rm = TRUE))) %>% 
  # consolidate the threat data into a clean dataframe
  dplyr::select(region, site, season, obs_date, obs_date2, obs_lon, obs_lat, 
         humans, vehicles, dogs, dogs_on, dogs_off, hoofed_animals, pred_birds,
         gulls, hum_pri, fox_pri, dog_pri, vehicle_pri, hoofed_pri) %>% 
  ungroup()
saveRDS(threat_data_, file = "output/threat_data_(all_years).rds")

Visual inspection of threat data

determine the 99% quantile limit for each threat (i.e., to remove outlier data) - shown as the red vertical line here

Code
# determine the 99% quantile limit for each threat (i.e., to remove outlier data)
threat_data_99_ql <- 
  threat_data_ %>% 
  summarise_at(c("humans", "vehicles", "dogs", "dogs_on", "dogs_off", "hoofed_animals", "pred_birds", "gulls"), 
               ~ quantile(.x, probs = c(0.99)))

threat_data_99_ql
# A tibble: 1 × 8
  humans vehicles  dogs dogs_on dogs_off hoofed_animals pred_birds gulls
   <dbl>    <dbl> <dbl>   <dbl>    <dbl>          <dbl>      <dbl> <dbl>
1     68        5    16       8       10              1          8   200
Code
# check histograms of threat data while inspecting the 99% cut-off
threat_data_ %>% 
  ggplot() +
  geom_histogram(aes(log(humans + 1))) +
  geom_vline(xintercept = log(as.numeric(threat_data_99_ql$humans[1])), color = "red") +
  luke_theme

Code
threat_data_ %>% 
  ggplot() +
  geom_histogram(aes(log(dogs + 1))) +
  geom_vline(xintercept = log(as.numeric(threat_data_99_ql$dogs[1])), color = "red") +
  luke_theme

Code
threat_data_ %>% 
  ggplot() +
  geom_histogram(aes(log(pred_birds + 1))) +
  geom_vline(xintercept = log(as.numeric(threat_data_99_ql$pred_birds[1])), color = "red") +
  luke_theme

Code
threat_data_ %>% 
  ggplot() +
  geom_histogram(aes(log(gulls + 1))) +
  geom_vline(xintercept = log(as.numeric(threat_data_99_ql$pred_birds[1])), color = "red") +
  luke_theme

Code
threat_data_ %>% 
  ggplot() +
  geom_histogram(aes(log(vehicles))) +
  geom_vline(xintercept = log(as.numeric(threat_data_99_ql$vehicles[1])), color = "red") +
  luke_theme

Code
threat_data_ %>% 
  ggplot() +
  geom_histogram(aes(log(dogs_off + 1))) +
  geom_vline(xintercept = log(as.numeric(threat_data_99_ql$dogs_off[1])), color = "red") +
  luke_theme

Code
threat_data_ %>% 
  ggplot() +
  geom_histogram(aes(log(dogs_on + 1))) +
  geom_vline(xintercept = log(as.numeric(threat_data_99_ql$dogs_on[1])), color = "red") +
  luke_theme

Code
threat_data_ %>% 
  ggplot() +
  geom_histogram(aes(hoofed_animals)) +
  geom_vline(xintercept = as.numeric(threat_data_99_ql$hoofed_animals[1]), color = "red") +
  luke_theme

Extract holidays (an index of human disturbance)

Code
# extract public holidays and merge them to the threat data
#### FP ----
FP_holidays <-
  bind_rows(
    holiday_aus(2009, state = "SA"),
    holiday_aus(2010, state = "SA"),
    holiday_aus(2011, state = "SA"),
    holiday_aus(2012, state = "SA"),
    holiday_aus(2013, state = "SA"),
    holiday_aus(2014, state = "SA"),
    holiday_aus(2015, state = "SA"),
    holiday_aus(2016, state = "SA"),
    holiday_aus(2017, state = "SA"),
    holiday_aus(2018, state = "SA"),
    holiday_aus(2019, state = "SA"),
    holiday_aus(2020, state = "SA"),
    holiday_aus(2021, state = "SA"),
    holiday_aus(2022, state = "SA"),
    holiday_aus(2023, state = "SA"),
    holiday_aus(2024, state = "SA")) %>% 
  mutate(event = holiday) %>% 
  mutate(region = "FP",
         end_date = date) %>% 
  rename(start_date = date) %>% 
  mutate(year = year(start_date)) %>% 
  mutate(season = ifelse(month(start_date) < 6, year - 1, year)) %>% 
  mutate(season = ifelse(month(start_date) >= 6, 
                         paste0(year, substr(year + 1, 3, 4)), 
                         paste0(season, substr(year, 3, 4))))

SA_start_end_holidays <- 
  read_excel("data/School holiday dates.xlsx",
             sheet = "SA Sch. Hol Dates", 
             col_types = "text") %>% 
  separate(`Autumn school holiday dates`, 
           into = paste0("new_col", 1:5), sep = " ") %>% 
  mutate(autumn_start = as.Date(paste(Year, new_col2, new_col1, sep = "-"), 
                                format = "%Y-%b-%d"),
         autumn_end = as.Date(paste(Year, new_col5, new_col4, sep = "-"), 
                                format = "%Y-%b-%d")) %>% 
  dplyr::select(-c(new_col1:new_col5)) %>% 
  separate(`Winter school holiday dates`, 
           into = paste0("new_col", 1:5), sep = " ") %>% 
  mutate(winter_start = as.Date(paste(Year, new_col2, new_col1, sep = "-"), 
                                format = "%Y-%b-%d"),
         winter_end = as.Date(paste(Year, new_col5, new_col4, sep = "-"), 
                                format = "%Y-%b-%d")) %>% 
  dplyr::select(-c(new_col1:new_col5)) %>% 
  separate(`Spring school holiday dates`, 
           into = paste0("new_col", 1:5), sep = " ") %>% 
  mutate(spring_start = as.Date(paste(Year, new_col2, new_col1, sep = "-"), 
                                format = "%Y-%b-%d"),
         spring_end = as.Date(paste(Year, new_col5, new_col4, sep = "-"), 
                                format = "%Y-%b-%d")) %>% 
  dplyr::select(-c(new_col1:new_col5)) %>% 
  separate(`Summer school holiday dates`, 
           into = paste0("new_col", 1:5), sep = " ") %>% 
  mutate(summer_start = as.Date(paste(Year, new_col2, new_col1, sep = "-"), 
                                format = "%Y-%b-%d"),
         summer_end = as.Date(paste(as.character(as.numeric(Year)+1), new_col5, new_col4, sep = "-"), 
                                format = "%Y-%b-%d")) %>% 
  dplyr::select(-c(Year:Source))

FP_start_school_holidays <- 
  SA_start_end_holidays %>% 
  select(autumn_start, winter_start, spring_start, summer_start) %>% 
  pivot_longer(cols = everything(), names_to = "event") %>% 
  mutate(event = str_remove(event, "_start")) %>% 
  mutate(region = "FP") %>% 
  rename(start_date = value) %>% 
  mutate(year = year(start_date)) %>% 
  mutate(season = ifelse(month(start_date) < 6, year - 1, year)) %>% 
  mutate(season = ifelse(month(start_date) >= 6, 
                         paste0(year, substr(year+1, 3, 4)), 
                         paste0(season, substr(year, 3, 4))))

FP_school_holidays <- 
  SA_start_end_holidays %>% 
  select(autumn_end, winter_end, spring_end, summer_end) %>% 
  pivot_longer(cols = everything(), names_to = "event") %>% 
  mutate(event = str_remove(event, "_end")) %>% 
  rename(end_date = value) %>% 
  mutate(year = year(end_date)) %>% 
  mutate(season = ifelse(month(end_date) < 6, year - 1, year)) %>% 
  mutate(season = ifelse(month(end_date) >= 6, 
                         paste0(year, substr(year+1, 3, 4)), 
                         paste0(season, substr(year, 3, 4)))) %>% 
  left_join(FP_start_school_holidays, ., by = c("season", "event")) %>% 
  mutate(event = paste(event, "school", sep = "_")) %>% 
  select(-c(year.x, year.y))

FP_holidays <- 
  bind_rows(FP_school_holidays, FP_holidays) %>% 
  select(season, region, event, start_date, end_date) %>% 
  arrange(start_date)

#### MP ----
MP_holidays <-
  bind_rows(
    holiday_aus(2006, state = "VIC"),
    holiday_aus(2007, state = "VIC"),
    holiday_aus(2008, state = "VIC"),
    holiday_aus(2009, state = "VIC"),
    holiday_aus(2010, state = "VIC"),
    holiday_aus(2011, state = "VIC"),
    holiday_aus(2012, state = "VIC"),
    holiday_aus(2013, state = "VIC"),
    holiday_aus(2014, state = "VIC"),
    holiday_aus(2015, state = "VIC"),
    holiday_aus(2016, state = "VIC"),
    holiday_aus(2017, state = "VIC"),
    holiday_aus(2018, state = "VIC"),
    holiday_aus(2019, state = "VIC"),
    holiday_aus(2020, state = "VIC"),
    holiday_aus(2021, state = "VIC"),
    holiday_aus(2022, state = "VIC"),
    holiday_aus(2023, state = "VIC"),
    holiday_aus(2024, state = "VIC")) %>% 
  mutate(event = holiday) %>% 
  mutate(region = "MP",
         end_date = date) %>% 
  rename(start_date = date) %>% 
  mutate(year = year(start_date)) %>% 
  mutate(season = ifelse(month(start_date) < 6, year - 1, year)) %>% 
  mutate(season = ifelse(month(start_date) >= 6, 
                         paste0(year, substr(year + 1, 3, 4)), 
                         paste0(season, substr(year, 3, 4))))

VIC_start_end_holidays <- 
  read_excel("data/School holiday dates.xlsx",
             sheet = "VIC Sch. Hol. Dates", 
             col_types = "text") %>% 
  separate(`Autumn school holiday dates`, 
           into = paste0("new_col", 1:5), sep = " ") %>% 
  mutate(autumn_start = as.Date(paste(Year, new_col2, new_col1, sep = "-"), 
                                format = "%Y-%b-%d"),
         autumn_end = as.Date(paste(Year, new_col5, new_col4, sep = "-"), 
                                format = "%Y-%b-%d")) %>% 
  dplyr::select(-c(new_col1:new_col5)) %>% 
  separate(`Winter school holiday dates`, 
           into = paste0("new_col", 1:5), sep = " ") %>% 
  mutate(winter_start = as.Date(paste(Year, new_col2, new_col1, sep = "-"), 
                                format = "%Y-%b-%d"),
         winter_end = as.Date(paste(Year, new_col5, new_col4, sep = "-"), 
                                format = "%Y-%b-%d")) %>% 
  dplyr::select(-c(new_col1:new_col5)) %>% 
  separate(`Spring school holiday dates`, 
           into = paste0("new_col", 1:5), sep = " ") %>% 
  mutate(spring_start = as.Date(paste(Year, new_col2, new_col1, sep = "-"), 
                                format = "%Y-%b-%d"),
         spring_end = as.Date(paste(Year, new_col5, new_col4, sep = "-"), 
                                format = "%Y-%b-%d")) %>% 
  dplyr::select(-c(new_col1:new_col5)) %>% 
  separate(`Summer school holiday dates`, 
           into = paste0("new_col", 1:5), sep = " ") %>% 
  mutate(summer_start = as.Date(paste(Year, new_col2, new_col1, sep = "-"), 
                                format = "%Y-%b-%d"),
         summer_end = as.Date(paste(as.character(as.numeric(Year)+1), new_col5, new_col4, sep = "-"), 
                                format = "%Y-%b-%d")) %>% 
  dplyr::select(-c(Year:Source))

MP_start_school_holidays <- 
  VIC_start_end_holidays %>% 
  select(autumn_start, winter_start, spring_start, summer_start) %>% 
  pivot_longer(cols = everything(), names_to = "event") %>% 
  mutate(event = str_remove(event, "_start")) %>% 
  mutate(region = "FP") %>% 
  rename(start_date = value) %>% 
  mutate(year = year(start_date)) %>% 
  mutate(season = ifelse(month(start_date) < 6, year - 1, year)) %>% 
  mutate(season = ifelse(month(start_date) >= 6, 
                         paste0(year, substr(year+1, 3, 4)), 
                         paste0(season, substr(year, 3, 4))))

MP_school_holidays <- 
  VIC_start_end_holidays %>% 
  select(autumn_end, winter_end, spring_end, summer_end) %>% 
  pivot_longer(cols = everything(), names_to = "event") %>% 
  mutate(event = str_remove(event, "_end")) %>% 
  rename(end_date = value) %>% 
  mutate(year = year(end_date)) %>% 
  mutate(season = ifelse(month(end_date) < 6, year - 1, year)) %>% 
  mutate(season = ifelse(month(end_date) >= 6, 
                         paste0(year, substr(year+1, 3, 4)), 
                         paste0(season, substr(year, 3, 4)))) %>% 
  left_join(MP_start_school_holidays, ., by = c("season", "event")) %>% 
  mutate(event = paste(event, "school", sep = "_")) %>% 
  select(-c(year.x, year.y)) %>% arrange(start_date)

MP_holidays <- 
  bind_rows(MP_school_holidays, MP_holidays) %>% 
  select(season, region, event, start_date, end_date) %>% 
  arrange(start_date)

BSC_holidays <- 
  bind_rows(MP_school_holidays, MP_holidays) %>% 
  select(season, region, event, start_date, end_date) %>% 
  arrange(start_date) %>% 
  mutate(region = "BSC")

holidays <- 
  bind_rows(FP_holidays, BSC_holidays, MP_holidays)# %>% 
  # pivot_longer(-c(season:holiday), names_to = "start_end", values_to = "date")

Extract Weekdays (another index of human disturbance)

Code
threat_data__ <-
  threat_data_ %>% 
  mutate(season_site = paste(season, site, sep = "_"),
         weekday = factor(as.factor(weekdays(obs_date)), 
                          levels = c("Monday", "Tuesday", "Wednesday", 
                                     "Thursday", "Friday", "Saturday", 
                                     "Sunday"))) %>% 
  rename(date = obs_date) %>% 
  left_join(., holidays, by = c("region", "season"), relationship = "many-to-many") %>%
  mutate(holiday = ifelse(date >= start_date & date <= end_date, 1, 0)) %>% 
  # dplyr::select(region, season, site, date, start_date, end_date, event, holiday) %>% distinct() %>% 
  group_by(region, season, site, date) %>% 
  mutate(holiday = max(holiday, na.rm = TRUE)) %>% 
  dplyr::select(-c(event, start_date, end_date)) %>% 
  distinct() %>% 
  ungroup() %>% 
  mutate(day_type = ifelse(holiday == 1 | weekday %in% 
                             c("Saturday", "Sunday"), "funday", "workday")) %>% 
  mutate(funday = ifelse(day_type == "funday", 1, 0)) %>% 
  mutate(humans_ = ifelse(humans > as.numeric(threat_data_99_ql$humans[1]), NA, humans),
         vehicles_ = ifelse(vehicles > as.numeric(threat_data_99_ql$vehicles[1]), NA, vehicles),
         dogs_ = ifelse(dogs > as.numeric(threat_data_99_ql$dogs[1]), NA, dogs),
         dogs_off_ = ifelse(dogs_off > as.numeric(threat_data_99_ql$dogs_off[1]), NA, dogs_off),
         dogs_on_ = ifelse(dogs_on > as.numeric(threat_data_99_ql$dogs_on[1]), NA, dogs_on),
         hoofed_animals_ = ifelse(hoofed_animals > as.numeric(threat_data_99_ql$hoofed_animals[1]), NA, hoofed_animals),
         pred_birds_ = ifelse(pred_birds > as.numeric(threat_data_99_ql$pred_birds[1]), NA, pred_birds),
         gulls_ = ifelse(gulls > as.numeric(threat_data_99_ql$gulls[1]), NA, pred_birds)) %>% 
  mutate(weekdayN = as.numeric(weekday) - 1) %>% 
  mutate(weekdayC = circular::circular(weekdayN, type = "angles", units = "radians")) %>% 
  filter(!is.na(weekday))

threat_data__ %>% 
  ggplot() +
  geom_histogram(aes(funday)) +
  # geom_vline(xintercept = log(10), color = "red") +
  luke_theme

test if weekends and holidays have more threat counts than other days using zero-inflated models. For all threats, there are more counted on weekends and holidays than during the week, except for vehicles (which occur randomly across the week)

Code
#### test if weekends and holidays have more threat counts than other days
# use a zero-inflated model (https://stats.oarc.ucla.edu/r/dae/zip/)

# for all threats, there are more counted on weekends and holidays than during the week,
# except for vehicles (which occur randomly across the week)
mod_hum_zi <- pscl::zeroinfl(humans_ ~ day_type, data = threat_data__, dist = "poisson")
summary(mod_hum_zi)

Call:
pscl::zeroinfl(formula = humans_ ~ day_type, data = threat_data__, dist = "poisson")

Pearson residuals:
    Min      1Q  Median      3Q     Max 
-1.2268 -0.8575 -0.6754  0.2437 18.9597 

Count model coefficients (poisson with log link):
                 Estimate Std. Error z value Pr(>|z|)    
(Intercept)      2.313370   0.002680   863.3   <2e-16 ***
day_typeworkday -0.530996   0.004288  -123.8   <2e-16 ***

Zero-inflation model coefficients (binomial with logit link):
                Estimate Std. Error z value Pr(>|z|)    
(Intercept)     -0.66438    0.01461  -45.46   <2e-16 ***
day_typeworkday  0.68424    0.01855   36.89   <2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 

Number of iterations in BFGS optimization: 10 
Log-likelihood: -1.953e+05 on 4 Df
Code
mod_dogs_zi <- pscl::zeroinfl(dogs_ ~ day_type, data = threat_data__, dist = "poisson")
summary(mod_dogs_zi)

Call:
pscl::zeroinfl(formula = dogs_ ~ day_type, data = threat_data__, dist = "poisson")

Pearson residuals:
    Min      1Q  Median      3Q     Max 
-0.7049 -0.4952 -0.4952  0.1480  9.7953 

Count model coefficients (poisson with log link):
                 Estimate Std. Error z value Pr(>|z|)    
(Intercept)      1.341432   0.005714  234.77   <2e-16 ***
day_typeworkday -0.273367   0.009126  -29.95   <2e-16 ***

Zero-inflation model coefficients (binomial with logit link):
                Estimate Std. Error z value Pr(>|z|)    
(Intercept)      0.32806    0.01431   22.93   <2e-16 ***
day_typeworkday  0.69407    0.01968   35.27   <2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 

Number of iterations in BFGS optimization: 15 
Log-likelihood: -7.116e+04 on 4 Df
Code
mod_dogs_on_zi <- pscl::zeroinfl(dogs_on_ ~ day_type, data = threat_data__, dist = "poisson")
summary(mod_dogs_on_zi)

Call:
pscl::zeroinfl(formula = dogs_on_ ~ day_type, data = threat_data__, dist = "poisson")

Pearson residuals:
    Min      1Q  Median      3Q     Max 
-0.4963 -0.4963 -0.3307 -0.3307 10.2420 

Count model coefficients (poisson with log link):
                Estimate Std. Error z value Pr(>|z|)    
(Intercept)      0.74632    0.01048   71.21   <2e-16 ***
day_typeworkday -0.31557    0.01827  -17.27   <2e-16 ***

Zero-inflation model coefficients (binomial with logit link):
                Estimate Std. Error z value Pr(>|z|)    
(Intercept)      0.88885    0.01719   51.71   <2e-16 ***
day_typeworkday  0.74981    0.02585   29.00   <2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 

Number of iterations in BFGS optimization: 10 
Log-likelihood: -3.836e+04 on 4 Df
Code
mod_dogs_off_zi <- pscl::zeroinfl(dogs_off_ ~ day_type, data = threat_data__, dist = "poisson")
summary(mod_dogs_off_zi)

Call:
pscl::zeroinfl(formula = dogs_off_ ~ day_type, data = threat_data__, 
    dist = "poisson")

Pearson residuals:
    Min      1Q  Median      3Q     Max 
-0.5556 -0.5556 -0.4136 -0.4136  7.9769 

Count model coefficients (poisson with log link):
                 Estimate Std. Error z value Pr(>|z|)    
(Intercept)      1.039734   0.008028  129.51   <2e-16 ***
day_typeworkday -0.175061   0.012310  -14.22   <2e-16 ***

Zero-inflation model coefficients (binomial with logit link):
                Estimate Std. Error z value Pr(>|z|)    
(Intercept)      0.75727    0.01565   48.38   <2e-16 ***
day_typeworkday  0.58194    0.02182   26.67   <2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 

Number of iterations in BFGS optimization: 10 
Log-likelihood: -5.134e+04 on 4 Df
Code
mod_pred_birds_zi <- pscl::zeroinfl(pred_birds_ ~ day_type, data = threat_data__, dist = "poisson")
summary(mod_pred_birds_zi)

Call:
pscl::zeroinfl(formula = pred_birds_ ~ day_type, data = threat_data__, 
    dist = "poisson")

Pearson residuals:
    Min      1Q  Median      3Q     Max 
-0.3377 -0.3377 -0.3377 -0.3353  7.2706 

Count model coefficients (poisson with log link):
                Estimate Std. Error z value Pr(>|z|)    
(Intercept)      0.91204    0.01317  69.237   <2e-16 ***
day_typeworkday  0.01469    0.01701   0.863    0.388    

Zero-inflation model coefficients (binomial with logit link):
                Estimate Std. Error z value Pr(>|z|)    
(Intercept)      1.80141    0.02105  85.590   <2e-16 ***
day_typeworkday -0.01001    0.02728  -0.367    0.714    
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 

Number of iterations in BFGS optimization: 15 
Log-likelihood: -3.214e+04 on 4 Df
Code
mod_gulls_zi <- pscl::zeroinfl(gulls_ ~ day_type, data = threat_data__, dist = "poisson")
summary(mod_gulls_zi)

Call:
pscl::zeroinfl(formula = gulls_ ~ day_type, data = threat_data__, dist = "poisson")

Pearson residuals:
    Min      1Q  Median      3Q     Max 
-0.3552 -0.3552 -0.3552 -0.3520 72.5718 

Count model coefficients (poisson with log link):
                Estimate Std. Error z value Pr(>|z|)    
(Intercept)      1.26787    0.01028 123.389   <2e-16 ***
day_typeworkday -0.01016    0.01333  -0.763    0.446    

Zero-inflation model coefficients (binomial with logit link):
                Estimate Std. Error z value Pr(>|z|)    
(Intercept)      1.80463    0.02015  89.546   <2e-16 ***
day_typeworkday -0.02144    0.02609  -0.822    0.411    
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 

Number of iterations in BFGS optimization: 15 
Log-likelihood: -4.225e+04 on 4 Df
Code
mod_vehicles_zi <- pscl::zeroinfl(vehicles_ ~ day_type, data = threat_data__, dist = "poisson")
summary(mod_vehicles_zi)

Call:
pscl::zeroinfl(formula = vehicles_ ~ day_type, data = threat_data__, 
    dist = "poisson")

Pearson residuals:
    Min      1Q  Median      3Q     Max 
-0.1433 -0.1433 -0.1109 -0.1109 15.8593 

Count model coefficients (poisson with log link):
                 Estimate Std. Error z value Pr(>|z|)    
(Intercept)      0.627124   0.035422  17.704   <2e-16 ***
day_typeworkday -0.007152   0.051771  -0.138     0.89    

Zero-inflation model coefficients (binomial with logit link):
                Estimate Std. Error z value Pr(>|z|)    
(Intercept)      3.44709    0.04532  76.065  < 2e-16 ***
day_typeworkday  0.51482    0.06584   7.819 5.33e-15 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 

Number of iterations in BFGS optimization: 18 
Log-likelihood: -6586 on 4 Df

Fit circular GAM to weekly count data to assess trends over the week.

how do human counts vary over the week?

Code
#### Fit circular GAM to weekly count data ----
mod_hum <- 
  mgcv::gam(humans_ ~ s(weekdayN, bs = "cc", k = 7), data = threat_data__)
summary(mod_hum)

Family: gaussian 
Link function: identity 

Formula:
humans_ ~ s(weekdayN, bs = "cc", k = 7)

Parametric coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept)  4.44953    0.03633   122.5   <2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Approximate significance of smooth terms:
              edf Ref.df     F p-value    
s(weekdayN) 4.944      5 134.4  <2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

R-sq.(adj) =  0.0128   Deviance explained = 1.29%
GCV = 68.224  Scale est. = 68.216    n = 51687
Code
# estimate model predictions 
newdata_weekdays <- 
  data.frame(weekdayN = seq(0, 6))

# plot the weekly variation in the human counts
mod_hum_fits <- 
  predict(mod_hum, 
          newdata = newdata_weekdays, 
          type = 'response', se = TRUE)

mod_hum_predicts <-  
  data.frame(newdata_weekdays, mod_hum_fits) %>% 
  mutate(lower = fit - 1.96 * se.fit,
         upper = fit + 1.96 * se.fit) %>% 
  left_join(., threat_data__ %>% dplyr::select(weekdayN, weekday) %>% distinct(), by = "weekdayN")

threat_data__ %>%
  ggplot() +
  gghalves::geom_half_point(aes(x = weekday, y = log(humans_ + 1)),
      size = 1,
      width = 0.5,
      side = "l", 
      range_scale = .4, 
      alpha = 0.1, color = "grey70"
    ) + 
    gghalves::geom_half_boxplot(aes(x = weekday, y = log(humans_ + 1)),
      size = 0.5,
      width = 0.5,
      side = "r",
      alpha = 0.1, outlier.color = NA, color = "grey70"
    ) +
  # geom_smooth(aes(x = as.numeric(weekday), y = humans_), 
  #             method = lm, 
  #             formula = y ~ splines::bs(x, 5)) +
  geom_ribbon(data = mod_hum_predicts,
              aes(x = as.numeric(weekday), ymin = log(lower + 1), ymax = log(upper + 1))) +
  geom_line(data = mod_hum_predicts, aes(x = as.numeric(weekday), y = log(fit + 1)), color = "white") +
  luke_theme +
  xlab("day of the week") +
  ylab("number of humans counted (log)")

how do dog counts vary over the week?

Code
mod_dogs <- 
  mgcv::gam(dogs_ ~ s(weekdayN, bs = "cc", k = 7), data = threat_data__)
summary(mod_dogs)

Family: gaussian 
Link function: identity 

Formula:
dogs_ ~ s(weekdayN, bs = "cc", k = 7)

Parametric coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept)  1.10607    0.01031   107.3   <2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Approximate significance of smooth terms:
              edf Ref.df     F p-value    
s(weekdayN) 4.602      5 35.11  <2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

R-sq.(adj) =  0.00337   Deviance explained = 0.346%
GCV = 5.4949  Scale est. = 5.4943    n = 51728
Code
# plot the weekly variation in the dog counts
mod_dogs_fits <- 
  predict(mod_dogs, 
          newdata = newdata_weekdays, 
          type = 'response', se = TRUE)

mod_dogs_predicts <-  
  data.frame(newdata_weekdays, mod_dogs_fits) %>% 
  mutate(lower = fit - 1.96 * se.fit,
         upper = fit + 1.96 * se.fit) %>% 
  left_join(., threat_data__ %>% dplyr::select(weekdayN, weekday) %>% distinct(), by = "weekdayN")

threat_data__ %>% 
  ggplot() +
  gghalves::geom_half_point(aes(x = weekday, y = log(dogs_ + 1)),
      size = 1,
      width = 0.5,
      side = "l", 
      range_scale = .4, 
      alpha = 0.1
    ) + 
    gghalves::geom_half_boxplot(aes(x = weekday, y = log(dogs_ + 1)),
      size = 0.5,
      width = 0.5,
      side = "r",
      alpha = 0.1, outlier.color = NA
    ) +
  geom_ribbon(data = mod_dogs_predicts,
              aes(x = as.numeric(weekday), ymin = log(lower + 1), ymax = log(upper + 1))) +
  geom_line(data = mod_dogs_predicts, aes(x = as.numeric(weekday), y = log(fit + 1)), color = "white") +
  # geom_smooth(aes(x = as.numeric(weekday), y = dogs_), method = lm, formula = y ~ splines::bs(x, 5)) +
  luke_theme +
  xlab("day of the week") +
  ylab("number of dogs counted (log)")

how do dogs on leash counts vary over the week?

Code
mod_dogs_on <- 
  mgcv::gam(dogs_on_ ~ s(weekdayN, bs = "cc", k = 7), data = threat_data__)
summary(mod_dogs_on)

Family: gaussian 
Link function: identity 

Formula:
dogs_on_ ~ s(weekdayN, bs = "cc", k = 7)

Parametric coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept)  0.39752    0.00475   83.69   <2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Approximate significance of smooth terms:
              edf Ref.df     F p-value    
s(weekdayN) 4.549      5 29.16  <2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

R-sq.(adj) =  0.00279   Deviance explained = 0.288%
GCV = 1.1666  Scale est. = 1.1665    n = 51696
Code
# plot the weekly variation in the dog on leash counts
mod_dogs_on_fits <- 
  predict(mod_dogs_on, 
          newdata = newdata_weekdays, 
          type = 'response', se = TRUE)

mod_dogs_on_predicts <-  
  data.frame(newdata_weekdays, mod_dogs_on_fits) %>% 
  mutate(lower = fit - 1.96 * se.fit,
         upper = fit + 1.96 * se.fit) %>% 
  left_join(., threat_data__ %>% dplyr::select(weekdayN, weekday) %>% distinct(), by = "weekdayN")

threat_data__ %>% 
  ggplot() +
  gghalves::geom_half_point(aes(x = weekday, y = log(dogs_on_ + 1)),
      size = 1,
      width = 0.5,
      side = "l", 
      range_scale = .4, 
      alpha = 0.1
    ) + 
    gghalves::geom_half_boxplot(aes(x = weekday, y = log(dogs_on_ + 1)),
      size = 0.5,
      width = 0.5,
      side = "r",
      alpha = 0.1, outlier.color = NA
    ) +
  geom_ribbon(data = mod_dogs_on_predicts,
              aes(x = as.numeric(weekday), ymin = log(lower + 1), ymax = log(upper + 1))) +
  geom_line(data = mod_dogs_on_predicts, aes(x = as.numeric(weekday), y = log(fit + 1)), color = "white") +
  # geom_smooth(aes(x = as.numeric(weekday), y = dogs_on_), method = lm, formula = y ~ splines::bs(x, 5)) +
  luke_theme +
  xlab("day of the week") +
  ylab("number of dogs on leashes counted (log)")

how do dogs off leash counts vary over the week?

Code
mod_dogs_off <- 
  mgcv::gam(dogs_off_ ~ s(weekdayN, bs = "cc", k = 7), data = threat_data__)
summary(mod_dogs_off)

Family: gaussian 
Link function: identity 

Formula:
dogs_off_ ~ s(weekdayN, bs = "cc", k = 7)

Parametric coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept) 0.658748   0.006876   95.81   <2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Approximate significance of smooth terms:
              edf Ref.df     F p-value    
s(weekdayN) 4.294      5 20.52  <2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

R-sq.(adj) =  0.00197   Deviance explained = 0.206%
GCV = 2.4441  Scale est. = 2.4439    n = 51692
Code
# plot the weekly variation in the dog off leash counts
mod_dogs_off_fits <- 
  predict(mod_dogs_off, 
          newdata = newdata_weekdays, 
          type = 'response', se = TRUE)

mod_dogs_off_predicts <-  
  data.frame(newdata_weekdays, mod_dogs_off_fits) %>% 
  mutate(lower = fit - 1.96 * se.fit,
         upper = fit + 1.96 * se.fit) %>% 
  left_join(., threat_data__ %>% dplyr::select(weekdayN, weekday) %>% distinct(), by = "weekdayN")

threat_data__ %>% 
  ggplot() +
  gghalves::geom_half_point(aes(x = weekday, y = log(dogs_off_ + 1)),
      size = 1,
      width = 0.5,
      side = "l", 
      range_scale = .4, 
      alpha = 0.1
    ) + 
    gghalves::geom_half_boxplot(aes(x = weekday, y = log(dogs_off_ + 1)),
      size = 0.5,
      width = 0.5,
      side = "r",
      alpha = 0.1, outlier.color = NA
    ) +
  geom_ribbon(data = mod_dogs_off_predicts,
              aes(x = as.numeric(weekday), ymin = log(lower + 1), ymax = log(upper + 1))) +
  geom_line(data = mod_dogs_off_predicts, aes(x = as.numeric(weekday), y = log(fit + 1)), color = "white") +
  # geom_smooth(aes(x = as.numeric(weekday), y = dogs_off_), method = lm, formula = y ~ splines::bs(x, 5)) +
  luke_theme +
  xlab("day of the week") +
  ylab("number of dogs off leashes counted (log)")

how do corvid counts vary over the week?

Code
mod_pred_birds <- 
  mgcv::gam(pred_birds_ ~ s(weekdayN, bs = "cc", k = 7), data = threat_data__)
summary(mod_pred_birds)

Family: gaussian 
Link function: identity 

Formula:
pred_birds_ ~ s(weekdayN, bs = "cc", k = 7)

Parametric coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept) 0.357615   0.004885   73.21   <2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Approximate significance of smooth terms:
              edf Ref.df     F p-value  
s(weekdayN) 3.499      5 2.216  0.0105 *
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

R-sq.(adj) =  0.000184   Deviance explained = 0.0252%
GCV = 1.2342  Scale est. = 1.2341    n = 51726
Code
# plot the weekly variation in the predatory bird counts
mod_pred_birds_fits <- 
  predict(mod_pred_birds, 
          newdata = newdata_weekdays, 
          type = 'response', se = TRUE)

mod_pred_birds_predicts <-  
  data.frame(newdata_weekdays, mod_pred_birds_fits) %>% 
  mutate(lower = fit - 1.96 * se.fit,
         upper = fit + 1.96 * se.fit) %>% 
  left_join(., threat_data__ %>% dplyr::select(weekdayN, weekday) %>% distinct(), by = "weekdayN")

threat_data__ %>% 
  ggplot() +
  gghalves::geom_half_point(aes(x = weekday, y = log(pred_birds_ + 1)),
      size = 1,
      width = 0.5,
      side = "l", 
      range_scale = .4, 
      alpha = 0.1
    ) + 
    gghalves::geom_half_boxplot(aes(x = weekday, y = log(pred_birds_ + 1)),
      size = 0.5,
      width = 0.5,
      side = "r",
      alpha = 0.1, outlier.color = NA
    ) +
  geom_ribbon(data = mod_pred_birds_predicts,
              aes(x = as.numeric(weekday), ymin = log(lower + 1), ymax = log(upper + 1))) +
  geom_line(data = mod_pred_birds_predicts, aes(x = as.numeric(weekday), y = log(fit + 1)), color = "white") +
  # geom_smooth(aes(x = as.numeric(weekday), y = pred_birds_), method = lm, formula = y ~ splines::bs(x, 5)) +
  luke_theme +
  xlab("day of the week") +
  ylab("number of corvids counted (log)")

how do gulls counts vary over the week?

Code
mod_pred_birds <- 
  mgcv::gam(gulls_ ~ s(weekdayN, bs = "cc", k = 7), data = threat_data__)
summary(mod_pred_birds)

Family: gaussian 
Link function: identity 

Formula:
gulls_ ~ s(weekdayN, bs = "cc", k = 7)

Parametric coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept) 0.504499   0.009826   51.34   <2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Approximate significance of smooth terms:
              edf Ref.df     F p-value  
s(weekdayN) 3.838      5 2.229   0.015 *
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

R-sq.(adj) =  0.000187   Deviance explained = 0.0261%
GCV = 5.0009  Scale est. = 5.0004    n = 51794
Code
# plot the weekly variation in the predatory bird counts
mod_gulls_fits <- 
  predict(mod_pred_birds, 
          newdata = newdata_weekdays, 
          type = 'response', se = TRUE)

mod_gulls_predicts <-  
  data.frame(newdata_weekdays, mod_gulls_fits) %>% 
  mutate(lower = fit - 1.96 * se.fit,
         upper = fit + 1.96 * se.fit) %>% 
  left_join(., threat_data__ %>% dplyr::select(weekdayN, weekday) %>% distinct(), by = "weekdayN")

threat_data__ %>% 
  ggplot() +
  gghalves::geom_half_point(aes(x = weekday, y = log(gulls_ + 1)),
      size = 1,
      width = 0.5,
      side = "l", 
      range_scale = .4, 
      alpha = 0.1
    ) + 
    gghalves::geom_half_boxplot(aes(x = weekday, y = log(gulls_ + 1)),
      size = 0.5,
      width = 0.5,
      side = "r",
      alpha = 0.1, outlier.color = NA
    ) +
  geom_ribbon(data = mod_gulls_predicts,
              aes(x = as.numeric(weekday), ymin = log(lower + 1), ymax = log(upper + 1))) +
  geom_line(data = mod_gulls_predicts, aes(x = as.numeric(weekday), y = log(fit + 1)), color = "white") +
  # geom_smooth(aes(x = as.numeric(weekday), y = gulls_), method = lm, formula = y ~ splines::bs(x, 5)) +
  luke_theme +
  xlab("day of the week") +
  ylab("number of gulls counted (log)")

how do vehicle counts vary over the week?

Code
mod_vehicles <- 
  mgcv::gam(vehicles_ ~ s(weekdayN, bs = "cc", k = 7), data = threat_data__)
summary(mod_vehicles)

Family: gaussian 
Link function: identity 

Formula:
vehicles_ ~ s(weekdayN, bs = "cc", k = 7)

Parametric coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept) 0.044039   0.001587   27.74   <2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Approximate significance of smooth terms:
              edf Ref.df     F p-value  
s(weekdayN) 3.809      5 2.153  0.0175 *
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

R-sq.(adj) =  0.000174   Deviance explained = 0.0248%
GCV = 0.13025  Scale est. = 0.13023   n = 51682
Code
# plot the weekly variation in the vehicle counts
mod_vehicles_fits <- 
  predict(mod_vehicles, 
          newdata = newdata_weekdays, 
          type = 'response', se = TRUE)

mod_vehicles_predicts <-  
  data.frame(newdata_weekdays, mod_vehicles_fits) %>% 
  mutate(lower = fit - 1.96 * se.fit,
         upper = fit + 1.96 * se.fit) %>% 
  left_join(., threat_data__ %>% dplyr::select(weekdayN, weekday) %>% distinct(), by = "weekdayN")

threat_data__ %>% 
  ggplot() +
  gghalves::geom_half_point(aes(x = weekday, y = vehicles_),
      size = 1,
      width = 0.5,
      side = "l", 
      range_scale = .4, 
      alpha = 0.1
    ) + 
    gghalves::geom_half_boxplot(aes(x = weekday, y = vehicles_),
      size = 0.5,
      width = 0.5,
      side = "r",
      alpha = 0.1, outlier.color = NA
    ) +
  geom_ribbon(data = mod_vehicles_predicts,
              aes(x = as.numeric(weekday), ymin = lower, ymax = upper)) +
  geom_line(data = mod_vehicles_predicts, aes(x = as.numeric(weekday), y = fit), color = "white") +
  # geom_smooth(aes(x = as.numeric(weekday), y = vehicles_), method = lm, formula = y ~ splines::bs(x, 5)) +
  luke_theme +
  xlab("day of the week") +
  ylab("number of vehicles counted")

Inspect the weekly variation in human prints

Code
# plot the weekly variation in the human print detections
threat_data__ %>% 
  ggplot() +
  gghalves::geom_half_point(aes(x = weekday, y = hum_pri),
      size = 1,
      width = 0.5,
      side = "l", 
      range_scale = .4, 
      alpha = 0.1
    ) + 
    gghalves::geom_half_boxplot(aes(x = weekday, y = hum_pri),
      size = 0.5,
      width = 0.5,
      side = "r",
      alpha = 0.1, outlier.color = NA
    ) +
  geom_smooth(aes(x = as.numeric(weekday), y = hum_pri), method = lm, formula = y ~ splines::bs(x, 5)) +
  luke_theme +
  xlab("day of the week") +
  ylab("level of human prints recorded")

Inspect the weekly variation in dog prints

Code
# plot the weekly variation in the dog print detections
threat_data__ %>% 
  ggplot() +
  gghalves::geom_half_point(aes(x = weekday, y = dog_pri),
      size = 1,
      width = 0.5,
      side = "l", 
      range_scale = .4, 
      alpha = 0.1
    ) + 
    gghalves::geom_half_boxplot(aes(x = weekday, y = dog_pri),
      size = 0.5,
      width = 0.5,
      side = "r",
      alpha = 0.1, outlier.color = NA
    ) +
  geom_smooth(aes(x = as.numeric(weekday), y = dog_pri), method = lm, formula = y ~ splines::bs(x, 5)) +
  luke_theme +
  xlab("day of the week") +
  ylab("level of dogs prints recorded")

Inspect the weekly variation in vehicle prints

Code
# plot the weekly variation in the vehicle print detections
threat_data__ %>% 
  ggplot() +
  gghalves::geom_half_point(aes(x = weekday, y = vehicle_pri),
      size = 1,
      width = 0.5,
      side = "l", 
      range_scale = .4, 
      alpha = 0.1
    ) + 
    gghalves::geom_half_boxplot(aes(x = weekday, y = vehicle_pri),
      size = 0.5,
      width = 0.5,
      side = "r",
      alpha = 0.1, outlier.color = NA
    ) +
  geom_smooth(aes(x = as.numeric(weekday), y = vehicle_pri), method = lm, formula = y ~ splines::bs(x, 5)) +
  luke_theme +
  xlab("day of the week") +
  ylab("level of vehicle prints recorded")

Inspect the weekly variation in fox prints

Code
# plot the weekly variation in the fox print detections
threat_data__ %>% 
  ggplot() +
  gghalves::geom_half_point(aes(x = weekday, y = fox_pri),
      size = 1,
      width = 0.5,
      side = "l", 
      range_scale = .4, 
      alpha = 0.1
    ) + 
    gghalves::geom_half_boxplot(aes(x = weekday, y = fox_pri),
      size = 0.5,
      width = 0.5,
      side = "r",
      alpha = 0.1, outlier.color = NA
    ) +
  geom_smooth(aes(x = as.numeric(weekday), y = fox_pri), method = lm, formula = y ~ splines::bs(x, 5)) +
  luke_theme +
  xlab("day of the week") +
  ylab("level of fox prints recorded")

check correlation between counts of the various threats

Code
# check correlation between humans counts
threat_data__ %>% 
  dplyr::select(humans_, vehicles_, dogs_, pred_birds_) %>% 
  na.omit() %>% 
  cor() %>% 
  corrplot(type = "upper", method = "number", tl.srt = 45)

Code
# relationship between human counts and dog counts
threat_data__ %>% 
  ggplot() +
  geom_jitter(aes(x = humans_, y = dogs_), alpha = 0.1) +
  geom_smooth(aes(x = humans_, y = dogs_)) +#, method = lm, formula = y ~ splines::bs(x, 2)) +
  luke_theme +
  xlab("Number of humans counted") +
  ylab("Number of dogs counted")

Code
# relationship between human counts and corvid counts
threat_data__ %>% 
  ggplot() +
  geom_jitter(aes(x = humans_, y = pred_birds_), alpha = 0.1) +
  geom_smooth(aes(x = humans_, y = pred_birds_)) +#, method = lm) +
  luke_theme +
  xlab("Number of humans counted") +
  ylab("Number of corvids counted")

Code
# relationship between human counts and gull counts
threat_data__ %>% 
  ggplot() +
  geom_jitter(aes(x = humans_, y = gulls_), alpha = 0.1) +
  geom_smooth(aes(x = humans_, y = gulls_)) +#, method = lm) +
  luke_theme +
  xlab("Number of humans counted") +
  ylab("Number of gulls counted")

Code
# relationship between human counts and vehicle counts
threat_data__ %>% 
  ggplot() +
  geom_jitter(aes(x = humans_, y = vehicles_), alpha = 0.1) +
  geom_smooth(aes(x = humans_, y = vehicles_)) + #, method = lm, formula = y ~ splines::bs(x, 2)) +
  luke_theme +
  xlab("Number of humans counted") +
  ylab("Number of vehicles counted")

Code
# determine which territories are in the threat data and the nest data
sites_intersect_FP <- 
  inner_join(nest_data_FP, threat_data__ %>% filter(region == "FP"), by = c("season", "site"), relationship = "many-to-many") %>% 
  dplyr::select(season, site) %>% distinct() %>% 
  mutate(season_site = paste(season, site, sep = "_"))

sites_intersect_MP <- 
  inner_join(nest_data_MP, threat_data__ %>% filter(region == "MP"), by = c("season", "site"), relationship = "many-to-many") %>% 
  dplyr::select(season, site) %>% distinct() %>% 
  mutate(season_site = paste(season, site, sep = "_"))

sites_intersect_BSC <- 
  inner_join(nest_data_BSC, threat_data__ %>% filter(region == "BSC"), by = c("season", "site"), relationship = "many-to-many") %>% 
  dplyr::select(season, site) %>% distinct() %>% 
  mutate(season_site = paste(season, site, sep = "_"))

determine which site names are not mutually recognized between the nest and the threat data

Code
# FP
# Combine and classify unique season_site values
sites_diff_FP <- full_join(nest_data_FP %>% ungroup() %>% 
                             mutate(season_site = paste(season, site, sep = "_")) %>% 
                             select(season_site) %>% distinct() %>% mutate(source = "nest_data_FP"),
                           threat_data__ %>% ungroup() %>% filter(region == "FP")  %>%
                             mutate(season_site = paste(season, site, sep = "_")) %>% 
                             select(season_site) %>% distinct() %>% mutate(source = "threat_data_FP"),
                           by = "season_site")

# Find unique values in each dataframe
only_in_nest_data_FP <- 
  sites_diff_FP %>% 
  filter(is.na(source.y)) %>% 
  select(season_site) %>%
  # separate(season_site, into = c("season", "site"), sep = "_", extra = "merge") %>% 
  mutate(issue = "only in nest survival data")

only_in_threat_data_FP <-
  sites_diff_FP %>% 
  filter(is.na(source.x)) %>% 
  select(season_site) %>%
  # separate(season_site, into = c("season", "site"), sep = "_", extra = "merge") %>% 
  mutate(issue = "only in threat data")
  
# fuzzy matching and data cleaning
clean_text <- function(x) {
  x %>%
    str_replace_all("[^a-zA-Z0-9 _]", "") %>%  # Remove special characters but keep letters, numbers, and spaces
    str_replace_all("\\s+", "_") %>%         # Replace spaces with underscores
    tolower()                                 # Convert to lowercase
}

# Perform fuzzy join
fuzzy_result_FP <-
  stringdist_full_join(
    nest_data_FP %>% 
    ungroup() %>% 
    mutate(season_site = paste(season, site, sep = "_")) %>% 
    select(season_site) %>% distinct() %>% mutate(source = "nest_data_FP") %>% 
    mutate(season_site_clean = clean_text(season_site)), 
    threat_data__ %>% 
    ungroup() %>% 
    filter(region == "FP")  %>%
    mutate(season_site = paste(season, site, sep = "_")) %>% 
    select(season_site) %>% distinct() %>% mutate(source = "threat_data_FP") %>% 
    mutate(season_site_clean = clean_text(season_site)), 
    by = "season_site_clean", 
    method = "jw", # Jaro-Winkler distance
    max_dist = 0.2, # Adjust for optimal matching
    distance_col = "dist") %>% 
  left_join(., only_in_nest_data_FP, by = c("season_site.x" = "season_site")) %>% 
  left_join(., only_in_threat_data_FP, by = c("season_site.y" = "season_site")) %>% 
  mutate(nest_season = str_extract(season_site.x, "^\\d{6}"),
         threat_season = str_extract(season_site.y, "^\\d{6}")) %>% 
  filter(nest_season == threat_season) %>% 
  group_by(season_site.x) %>%
  slice_min(order_by = dist) %>%  # Keep only the best fuzzy match per season
  ungroup() %>% 
  mutate(site_nest_data = str_remove(season_site.x, "^\\d{6}_?"),
         site_threat_data = str_remove(season_site.y, "^\\d{6}_?")) %>% 
  filter(issue.x == "only in nest survival data") %>% 
  select(nest_season, site_nest_data, site_threat_data, dist) %>% 
  arrange(desc(dist)) %>% 
  rename(season = nest_season)

# Create a new workbook
sites_diff_FP_xl <- createWorkbook()

# Add each dataframe as a sheet
addWorksheet(sites_diff_FP_xl, "only_in_nest_data_FP")
writeData(sites_diff_FP_xl, "only_in_nest_data_FP", only_in_nest_data_FP)

addWorksheet(sites_diff_FP_xl, "only_in_threat_data_FP")
writeData(sites_diff_FP_xl, "only_in_threat_data_FP", only_in_threat_data_FP)

addWorksheet(sites_diff_FP_xl, "fuzzy_matches_to_consider")
writeData(sites_diff_FP_xl, "fuzzy_matches_to_consider", fuzzy_result_FP)

# Save the workbook
saveWorkbook(sites_diff_FP_xl, here("data/nest_issues_commented/site_names_issues_FP.xlsx"), overwrite = TRUE)

# MP
# Combine and classify unique season_site values
sites_diff_MP <- full_join(nest_data_MP %>% ungroup() %>% 
                             mutate(season_site = paste(season, site, sep = "_")) %>% 
                             select(season_site) %>% distinct() %>% mutate(source = "nest_data_MP"),
                           threat_data__ %>% ungroup() %>% filter(region == "MP")  %>%
                             mutate(season_site = paste(season, site, sep = "_")) %>% 
                             select(season_site) %>% distinct() %>% mutate(source = "threat_data_MP"),
                           by = "season_site")

# Find unique values in each dataframe
only_in_nest_data_MP <- 
  sites_diff_MP %>% 
  filter(is.na(source.y)) %>% 
  select(season_site) %>%
  # separate(season_site, into = c("season", "site"), sep = "_", extra = "merge") %>% 
  mutate(issue = "only in nest survival data")

only_in_threat_data_MP <-
  sites_diff_MP %>% 
  filter(is.na(source.x)) %>% 
  select(season_site) %>%
  # separate(season_site, into = c("season", "site"), sep = "_", extra = "merge") %>% 
  mutate(issue = "only in threat data")

# Perform fuzzy join
fuzzy_result_MP <-
  stringdist_full_join(
    nest_data_MP %>% 
    ungroup() %>% 
    mutate(season_site = paste(season, site, sep = "_")) %>% 
    select(season_site) %>% distinct() %>% mutate(source = "nest_data_MP") %>% 
    mutate(season_site_clean = clean_text(season_site)), 
    threat_data__ %>% 
    ungroup() %>% 
    filter(region == "MP")  %>%
    mutate(season_site = paste(season, site, sep = "_")) %>% 
    select(season_site) %>% distinct() %>% mutate(source = "threat_data_MP") %>% 
    mutate(season_site_clean = clean_text(season_site)), 
    by = "season_site_clean", 
    method = "jw", # Jaro-Winkler distance
    max_dist = 0.2, # Adjust for optimal matching
    distance_col = "dist") %>% 
  left_join(., only_in_nest_data_MP, by = c("season_site.x" = "season_site")) %>% 
  left_join(., only_in_threat_data_MP, by = c("season_site.y" = "season_site")) %>% 
  mutate(nest_season = str_extract(season_site.x, "^\\d{6}"),
         threat_season = str_extract(season_site.y, "^\\d{6}")) %>% 
  filter(nest_season == threat_season) %>% 
  group_by(season_site.x) %>%
  slice_min(order_by = dist) %>%  # Keep only the best fuzzy match per season
  ungroup() %>% 
  mutate(site_nest_data = str_remove(season_site.x, "^\\d{6}_?"),
         site_threat_data = str_remove(season_site.y, "^\\d{6}_?")) %>% 
  filter(issue.x == "only in nest survival data") %>% 
  select(nest_season, site_nest_data, site_threat_data, dist) %>% 
  arrange(desc(dist)) %>% 
  rename(season = nest_season)

# Create a new workbook
sites_diff_MP_xl <- createWorkbook()

# Add each dataframe as a sheet
addWorksheet(sites_diff_MP_xl, "only_in_nest_data_MP")
writeData(sites_diff_MP_xl, "only_in_nest_data_MP", only_in_nest_data_MP)

addWorksheet(sites_diff_MP_xl, "only_in_threat_data_MP")
writeData(sites_diff_MP_xl, "only_in_threat_data_MP", only_in_threat_data_MP)

addWorksheet(sites_diff_MP_xl, "fuzzy_matches_to_consider")
writeData(sites_diff_MP_xl, "fuzzy_matches_to_consider", fuzzy_result_MP)

# Save the workbook
saveWorkbook(sites_diff_MP_xl, here("data/nest_issues_commented/site_names_issues_MP.xlsx"), overwrite = TRUE)

# BSC
# Combine and classify unique season_site values
sites_diff_BSC <- full_join(nest_data_BSC %>% ungroup() %>% 
                             mutate(season_site = paste(season, site, sep = "_")) %>% 
                             select(season_site) %>% distinct() %>% mutate(source = "nest_data_BSC"),
                           threat_data__ %>% ungroup() %>% filter(region == "BSC")  %>%
                             mutate(season_site = paste(season, site, sep = "_")) %>% 
                             select(season_site) %>% distinct() %>% mutate(source = "threat_data_BSC"),
                           by = "season_site")

# Find unique values in each dataframe
only_in_nest_data_BSC <- 
  sites_diff_BSC %>% 
  filter(is.na(source.y)) %>% 
  select(season_site) %>%
  # separate(season_site, into = c("season", "site"), sep = "_", extra = "merge") %>% 
  mutate(issue = "only in nest survival data")

only_in_threat_data_BSC <-
  sites_diff_BSC %>% 
  filter(is.na(source.x)) %>% 
  select(season_site) %>%
  # separate(season_site, into = c("season", "site"), sep = "_", extra = "merge") %>% 
  mutate(issue = "only in threat data")

# Perform fuzzy join
fuzzy_result_BSC <-
  stringdist_full_join(
    nest_data_BSC %>% 
    ungroup() %>% 
    mutate(season_site = paste(season, site, sep = "_")) %>% 
    select(season_site) %>% distinct() %>% mutate(source = "nest_data_BSC") %>% 
    mutate(season_site_clean = clean_text(season_site)), 
    threat_data__ %>% 
    ungroup() %>% 
    filter(region == "BSC")  %>%
    mutate(season_site = paste(season, site, sep = "_")) %>% 
    select(season_site) %>% distinct() %>% mutate(source = "threat_data_BSC") %>% 
    mutate(season_site_clean = clean_text(season_site)), 
    by = "season_site_clean", 
    method = "jw", # Jaro-Winkler distance
    max_dist = 0.2, # Adjust for optimal matching
    distance_col = "dist") %>% 
  left_join(., only_in_nest_data_BSC, by = c("season_site.x" = "season_site")) %>% 
  left_join(., only_in_threat_data_BSC, by = c("season_site.y" = "season_site")) %>% 
  mutate(nest_season = str_extract(season_site.x, "^\\d{6}"),
         threat_season = str_extract(season_site.y, "^\\d{6}")) %>% 
  filter(nest_season == threat_season) %>% 
  group_by(season_site.x) %>%
  slice_min(order_by = dist) %>%  # Keep only the best fuzzy match per season
  ungroup() %>% 
  mutate(site_nest_data = str_remove(season_site.x, "^\\d{6}_?"),
         site_threat_data = str_remove(season_site.y, "^\\d{6}_?")) %>% 
  filter(issue.x == "only in nest survival data") %>% 
  select(nest_season, site_nest_data, site_threat_data, dist) %>% 
  arrange(desc(dist)) %>% 
  rename(season = nest_season)

# Create a new workbook
sites_diff_BSC_xl <- createWorkbook()

# Add each dataframe as a sheet
addWorksheet(sites_diff_BSC_xl, "only_in_nest_data_BSC")
writeData(sites_diff_BSC_xl, "only_in_nest_data_BSC", only_in_nest_data_BSC)

addWorksheet(sites_diff_BSC_xl, "only_in_threat_data_BSC")
writeData(sites_diff_BSC_xl, "only_in_threat_data_BSC", only_in_threat_data_BSC)

addWorksheet(sites_diff_BSC_xl, "fuzzy_matches_to_consider")
writeData(sites_diff_BSC_xl, "fuzzy_matches_to_consider", fuzzy_result_BSC)

# Save the workbook
saveWorkbook(sites_diff_BSC_xl, here("data/nest_issues_commented/site_names_issues_BSC.xlsx"), overwrite = TRUE)
  
nrow(fuzzy_result_BSC) + nrow(fuzzy_result_FP) + nrow(fuzzy_result_MP)
[1] 25

Summarise Threat data and Merge to Nest Data

Fleurieu Peninsula: summarise threat data

Code
nest_data_FP_with_threat_data <- 
  nest_data_FP %>% 
  mutate(season_site = paste(season, site, sep = "_")) %>% 
  filter(season_site %in% sites_intersect_FP$season_site) %>%
  dplyr::select(season, site, region, nest_ID, 
                FirstFound, LastPresent, LastChecked,
                first_found2, last_alive2, last_checked2,
                management_status, management_level,
                nest_hab, Fate) %>% 
  rename(status = management_status,
         level = management_level) %>% 
  mutate(level = paste0("L", level)) %>% 
  mutate(level = factor(level, 
                        levels = c("L0", "L1", 
                                   "L2", "L3", 
                                   "L4"))) %>% 
  ungroup() %>% 
  mutate(
    hum_a = NA,
    veh_a = NA,
    dog_a = NA,
    don_a = NA,
    dof_a = NA,
    hof_a = NA,
    pbd_a = NA,
    gul_a = NA,
    hum_m = NA,
    veh_m = NA,
    dog_m = NA,
    don_m = NA,
    dof_m = NA,
    hof_m = NA,
    pbd_m = NA,
    gul_m = NA,
    hum_b = NA,
    veh_b = NA,
    dog_b = NA,
    don_b = NA,
    dof_b = NA,
    pbd_b = NA,
    gul_b = NA,
    hof_b = NA,
    hum_p = NA,
    veh_p = NA,
    dog_p = NA,
    hof_p = NA,
    fox_p = NA,
    n_surveys = NA,
    days_active = NA,
    fundays = NA, 
    uncertain_days = NA,
    halfway = NA) %>% 
  filter(FirstFound <= LastPresent & FirstFound <= LastChecked & LastPresent <= LastChecked) %>% 
  filter(first_found2 <= last_alive2 & first_found2 <= last_checked2 & last_alive2 <= last_checked2)

FP_threat_data_subset <- 
  threat_data__ %>% 
  filter(region == "FP") %>% 
  mutate(season_site = paste(season, site, sep = "_")) %>% 
  filter(season_site %in% sites_intersect_FP$season_site) %>%
  ungroup()

for(i in 1:nrow(nest_data_FP_with_threat_data)){
  FirstFound <- nest_data_FP_with_threat_data$FirstFound[i]
  LastPresent <- nest_data_FP_with_threat_data$LastPresent[i]
  LastChecked <- nest_data_FP_with_threat_data$LastChecked[i]
  FirstFound2 <- nest_data_FP_with_threat_data$first_found2[i]
  LastPresent2 <- nest_data_FP_with_threat_data$last_alive2[i]
  LastChecked2 <- nest_data_FP_with_threat_data$last_checked2[i]
  halfway <- (LastChecked - LastPresent)/2
  days_active <- (LastPresent + halfway) - FirstFound
  uncertain_days <- LastChecked - LastPresent
  site_ <- as.character(nest_data_FP_with_threat_data$site[i])
  season_ <- as.character(nest_data_FP_with_threat_data$season[i])
  
  fundays_df <- 
    data.frame(date = seq(from = LastPresent2, to = LastChecked2, 1)) %>% 
    # mutate(weekday = weekdays(dates)) %>% 
    mutate(weekday = factor(as.factor(weekdays(date)), 
                            levels = c("Monday", "Tuesday", "Wednesday", 
                                       "Thursday", "Friday", "Saturday", 
                                       "Sunday")),
           region = "FP") %>% 
    mutate(year = year(date)) %>% 
    mutate(season = ifelse(month(date) < 6, year - 1, year)) %>% 
    mutate(season = ifelse(month(date) >= 6, 
                           paste0(year, substr(year + 1, 3, 4)), 
                           paste0(season, substr(year, 3, 4)))) %>% 
    left_join(., holidays, by = c("region", "season"), relationship = "many-to-many") %>%
    mutate(holiday = ifelse(date >= start_date & date <= end_date, 1, 0)) %>% 
    group_by(region, season, date) %>% 
    mutate(holiday = max(holiday, na.rm = TRUE)) %>% 
    dplyr::select(-c(event, start_date, end_date)) %>% 
    distinct() %>% 
    ungroup() %>% 
    mutate(day_type = ifelse(holiday == 1 | weekday %in% 
                               c("Saturday", "Sunday"), "funday", "workday")) %>% 
    mutate(funday = ifelse(day_type == "funday", 1, 0))
    
  FP_threat_data_subset_ <- 
    FP_threat_data_subset %>% 
    ungroup() %>% 
    # data.frame() %>% 
    # dplyr::filter(as.numeric(obs_date2) >= FirstFound & as.numeric(obs_date2) <= (LastPresent + halfway) & season == season_) %>%
    # dplyr::filter(as.numeric(obs_date2) >= LastPresent & as.numeric(obs_date2) <= (LastPresent + halfway) & season == season_) %>%
    dplyr::filter(as.numeric(obs_date2) >= LastPresent & as.numeric(obs_date2) <= (LastPresent + (LastChecked - LastPresent)) & season == season_) %>%
    dplyr::filter(site == site_)
  
  if(nrow(FP_threat_data_subset_) > 0){
    avgeraged_threats <-
      FP_threat_data_subset_ %>% 
      mutate(hum_bi = ifelse(humans > 0 | (!is.na(hum_pri)), 1, 0),
             vehicle_bi = ifelse(vehicles > 0 | (!is.na(vehicle_pri)), 1, 0),
             dogs_bi = ifelse(dogs > 0 | (!is.na(dog_pri)), 1, 0),
             dogs_off_bi = ifelse(dogs_off > 0, 1, 0),
             dogs_on_bi = ifelse(dogs_on > 0, 1, 0),
             p_birds_bi = ifelse(pred_birds > 0, 1, 0),
             gulls_bi = ifelse(gulls > 0, 1, 0),
             hoof_bi = ifelse(hoofed_animals > 0 | (!is.na(hoofed_pri)), 1, 0)) %>%
      dplyr::summarise(
        # fundays = sum(funday),
        hum_avg = mean(humans, na.rm = TRUE),
        vehicles_avg = mean(vehicles, na.rm = TRUE),
        dogs_avg = mean(dogs, na.rm = TRUE),
        dogs_on_avg = mean(dogs_on, na.rm = TRUE),
        dogs_off_avg = mean(dogs_off, na.rm = TRUE),
        hoof_avg = mean(hoofed_animals, na.rm = TRUE),
        p_birds_avg = mean(pred_birds, na.rm = TRUE),
        gulls_avg = mean(gulls, na.rm = TRUE),
        hum_max = max(humans, na.rm = TRUE),
        vehicles_max = max(vehicles, na.rm = TRUE),
        dogs_max = max(dogs, na.rm = TRUE),
        dogs_on_max = max(dogs_on, na.rm = TRUE),
        dogs_off_max = max(dogs_off, na.rm = TRUE),
        hoof_max = max(hoofed_animals, na.rm = TRUE),
        p_birds_max = max(pred_birds, na.rm = TRUE),
        gulls_max = max(gulls, na.rm = TRUE),
        hum_bi = max(hum_bi, na.rm = TRUE),
        vehicle_bi = max(vehicle_bi, na.rm = TRUE),
        dogs_bi = max(dogs_bi, na.rm = TRUE),
        dogs_on_bi = max(dogs_on_bi, na.rm = TRUE),
        dogs_off_bi = max(dogs_off_bi, na.rm = TRUE),
        p_birds_bi = max(p_birds_bi, na.rm = TRUE),
        gulls_bi = max(gulls_bi, na.rm = TRUE),
        hoof_bi = max(hoof_bi, na.rm = TRUE),
        hum_pr = max(hum_pri, na.rm = TRUE),
        vehicle_pr = max(vehicle_pri, na.rm = TRUE),
        dog_pr = max(dog_pri, na.rm = TRUE),
        hoof_pr = max(hoofed_pri, na.rm = TRUE),
        fox_pr = max(fox_pri, na.rm = TRUE),
        n_surveys = n(),
        days_active = days_active,
        halfway = halfway, 
        uncertain_days = uncertain_days)
    
    nest_data_FP_with_threat_data$fundays[i] <- sum(fundays_df$funday)
    nest_data_FP_with_threat_data$hum_a[i] <- avgeraged_threats$hum_avg
    nest_data_FP_with_threat_data$veh_a[i] <- avgeraged_threats$vehicles_avg
    nest_data_FP_with_threat_data$dog_a[i] <- avgeraged_threats$dogs_avg
    nest_data_FP_with_threat_data$don_a[i] <- avgeraged_threats$dogs_on_avg
    nest_data_FP_with_threat_data$dof_a[i] <- avgeraged_threats$dogs_off_avg
    nest_data_FP_with_threat_data$hof_a[i] <- avgeraged_threats$hoof_avg
    nest_data_FP_with_threat_data$pbd_a[i] <- avgeraged_threats$p_birds_avg
    nest_data_FP_with_threat_data$gul_a[i] <- avgeraged_threats$gulls_avg
    
    nest_data_FP_with_threat_data$hum_m[i] <- avgeraged_threats$hum_max
    nest_data_FP_with_threat_data$veh_m[i] <- avgeraged_threats$vehicles_max
    nest_data_FP_with_threat_data$dog_m[i] <- avgeraged_threats$dogs_max
    nest_data_FP_with_threat_data$don_m[i] <- avgeraged_threats$dogs_on_max
    nest_data_FP_with_threat_data$dof_m[i] <- avgeraged_threats$dogs_off_max
    nest_data_FP_with_threat_data$hof_m[i] <- avgeraged_threats$hoof_max
    nest_data_FP_with_threat_data$pbd_m[i] <- avgeraged_threats$p_birds_max
    nest_data_FP_with_threat_data$gul_m[i] <- avgeraged_threats$gulls_max
    
    nest_data_FP_with_threat_data$hum_b[i] <- avgeraged_threats$hum_bi
    nest_data_FP_with_threat_data$veh_b[i] <- avgeraged_threats$vehicle_bi
    nest_data_FP_with_threat_data$dog_b[i] <- avgeraged_threats$dogs_bi
    nest_data_FP_with_threat_data$don_b[i] <- avgeraged_threats$dogs_on_bi
    nest_data_FP_with_threat_data$dof_b[i] <- avgeraged_threats$dogs_off_bi
    nest_data_FP_with_threat_data$pbd_b[i] <- avgeraged_threats$p_birds_bi
    nest_data_FP_with_threat_data$hof_b[i] <- avgeraged_threats$hoof_bi
    nest_data_FP_with_threat_data$gul_b[i] <- avgeraged_threats$gulls_bi
    
    nest_data_FP_with_threat_data$hum_p[i] <- avgeraged_threats$hum_pr
    nest_data_FP_with_threat_data$veh_p[i] <- avgeraged_threats$vehicle_pr
    nest_data_FP_with_threat_data$dog_p[i] <- avgeraged_threats$dog_pr
    nest_data_FP_with_threat_data$hof_p[i] <- avgeraged_threats$hoof_pr
    nest_data_FP_with_threat_data$fox_p[i] <- avgeraged_threats$fox_pr
    
    nest_data_FP_with_threat_data$n_surveys[i] <- avgeraged_threats$n_surveys
    nest_data_FP_with_threat_data$days_active[i] <- avgeraged_threats$days_active
    nest_data_FP_with_threat_data$halfway[i] <- avgeraged_threats$halfway
    nest_data_FP_with_threat_data$uncertain_days[i] <- avgeraged_threats$uncertain_days

    
  }else{
    nest_data_FP_with_threat_data$hum_a[i] <- NA
    nest_data_FP_with_threat_data$veh_a[i] <- NA
    nest_data_FP_with_threat_data$dog_a[i] <- NA
    nest_data_FP_with_threat_data$don_a[i] <- NA
    nest_data_FP_with_threat_data$dof_a[i] <- NA
    nest_data_FP_with_threat_data$hof_a[i] <- NA
    nest_data_FP_with_threat_data$pbd_a[i] <- NA
    nest_data_FP_with_threat_data$gul_a[i] <- NA
    nest_data_FP_with_threat_data$hum_m[i] <- NA
    nest_data_FP_with_threat_data$veh_m[i] <- NA
    nest_data_FP_with_threat_data$dog_m[i] <- NA
    nest_data_FP_with_threat_data$don_m[i] <- NA
    nest_data_FP_with_threat_data$dof_m[i] <- NA
    nest_data_FP_with_threat_data$hof_m[i] <- NA
    nest_data_FP_with_threat_data$pbd_m[i] <- NA
    nest_data_FP_with_threat_data$gul_m[i] <- NA
    nest_data_FP_with_threat_data$hum_b[i] <- NA
    nest_data_FP_with_threat_data$veh_b[i] <- NA
    nest_data_FP_with_threat_data$dog_b[i] <- NA
    nest_data_FP_with_threat_data$don_b[i] <- NA
    nest_data_FP_with_threat_data$dof_b[i] <- NA
    nest_data_FP_with_threat_data$pbd_b[i] <- NA
    nest_data_FP_with_threat_data$gul_b[i] <- NA
    nest_data_FP_with_threat_data$hof_b[i] <- NA
    nest_data_FP_with_threat_data$hum_p[i] <- NA
    nest_data_FP_with_threat_data$veh_p[i] <- NA
    nest_data_FP_with_threat_data$dog_p[i] <- NA
    nest_data_FP_with_threat_data$hof_p[i] <- NA
    nest_data_FP_with_threat_data$fox_p[i] <- NA
    nest_data_FP_with_threat_data$n_surveys[i] <- 0
    nest_data_FP_with_threat_data$days_active[i] <- days_active
    nest_data_FP_with_threat_data$halfway[i] <- halfway
    nest_data_FP_with_threat_data$uncertain_days[i] <- uncertain_days
    nest_data_FP_with_threat_data$fundays[i] <- NA
  }
}
saveRDS(nest_data_FP_with_threat_data, file = "output/nest_data_FP_with_threat_data.rds")

Mornington Peninsula: summarise threat data

Code
nest_data_MP_with_threat_data <- 
  nest_data_MP %>% 
  mutate(season_site = paste(season, site, sep = "_")) %>% 
  filter(season_site %in% sites_intersect_MP$season_site) %>%
  dplyr::select(season, site, region, nest_ID, 
                FirstFound, LastPresent, LastChecked,
                first_found2, last_alive2, last_checked2,
                management_status, management_level,
                nest_hab, Fate) %>% 
  rename(status = management_status,
         level = management_level) %>% 
  mutate(level = paste0("L", level)) %>% 
  mutate(level = factor(level, 
                        levels = c("L0", "L1", 
                                   "L2", "L3", 
                                   "L4"))) %>% 
  ungroup() %>% 
  mutate(
    hum_a = NA,
    veh_a = NA,
    dog_a = NA,
    don_a = NA,
    dof_a = NA,
    hof_a = NA,
    pbd_a = NA,
    gul_a = NA,
    hum_m = NA,
    veh_m = NA,
    dog_m = NA,
    don_m = NA,
    dof_m = NA,
    hof_m = NA,
    pbd_m = NA,
    gul_m = NA,
    hum_b = NA,
    veh_b = NA,
    dog_b = NA,
    don_b = NA,
    dof_b = NA,
    pbd_b = NA,
    gul_b = NA,
    hof_b = NA,
    hum_p = NA,
    veh_p = NA,
    dog_p = NA,
    hof_p = NA,
    fox_p = NA,
    n_surveys = NA,
    days_active = NA,
    fundays = NA, 
    uncertain_days = NA,
    halfway = NA) %>% 
  filter(FirstFound <= LastPresent & FirstFound <= LastChecked & LastPresent <= LastChecked) %>% 
  filter(first_found2 <= last_alive2 & first_found2 <= last_checked2 & last_alive2 <= last_checked2)

MP_threat_data_subset <- 
  threat_data__ %>% 
  filter(region == "MP") %>% 
  mutate(season_site = paste(season, site, sep = "_")) %>% 
  filter(season_site %in% sites_intersect_MP$season_site) %>%
  ungroup()

for(i in 1:nrow(nest_data_MP_with_threat_data)){
  FirstFound <- nest_data_MP_with_threat_data$FirstFound[i]
  LastPresent <- nest_data_MP_with_threat_data$LastPresent[i]
  LastChecked <- nest_data_MP_with_threat_data$LastChecked[i]
  FirstFound2 <- nest_data_MP_with_threat_data$first_found2[i]
  LastPresent2 <- nest_data_MP_with_threat_data$last_alive2[i]
  LastChecked2 <- nest_data_MP_with_threat_data$last_checked2[i]
  halfway <- (LastChecked - LastPresent)/2
  days_active <- (LastPresent + halfway) - FirstFound
  uncertain_days <- LastChecked - LastPresent
  site_ <- as.character(nest_data_MP_with_threat_data$site[i])
  season_ <- as.character(nest_data_MP_with_threat_data$season[i])
  
  fundays_df <- 
    data.frame(date = seq(from = LastPresent2, to = LastChecked2, 1)) %>% 
    # mutate(weekday = weekdays(dates)) %>% 
    mutate(weekday = factor(as.factor(weekdays(date)), 
                            levels = c("Monday", "Tuesday", "Wednesday", 
                                       "Thursday", "Friday", "Saturday", 
                                       "Sunday")),
           region = "MP") %>% 
    mutate(year = year(date)) %>% 
    mutate(season = ifelse(month(date) < 6, year - 1, year)) %>% 
    mutate(season = ifelse(month(date) >= 6, 
                           paste0(year, substr(year + 1, 3, 4)), 
                           paste0(season, substr(year, 3, 4)))) %>% 
    left_join(., holidays, by = c("region", "season"), relationship = "many-to-many") %>%
    mutate(holiday = ifelse(date >= start_date & date <= end_date, 1, 0)) %>% 
    group_by(region, season, date) %>% 
    mutate(holiday = max(holiday, na.rm = TRUE)) %>% 
    dplyr::select(-c(event, start_date, end_date)) %>% 
    distinct() %>% 
    ungroup() %>% 
    mutate(day_type = ifelse(holiday == 1 | weekday %in% 
                               c("Saturday", "Sunday"), "funday", "workday")) %>% 
    mutate(funday = ifelse(day_type == "funday", 1, 0))
    
  MP_threat_data_subset_ <- 
    MP_threat_data_subset %>% 
    ungroup() %>% 
    # data.frame() %>% 
    # dplyr::filter(as.numeric(obs_date2) >= FirstFound & as.numeric(obs_date2) <= (LastPresent + halfway) & season == season_) %>%
    # dplyr::filter(as.numeric(obs_date2) >= LastPresent & as.numeric(obs_date2) <= (LastPresent + halfway) & season == season_) %>%
    dplyr::filter(as.numeric(obs_date2) >= LastPresent & as.numeric(obs_date2) <= (LastPresent + (LastChecked - LastPresent)) & season == season_) %>%
    dplyr::filter(site == site_)
  
  if(nrow(MP_threat_data_subset_) > 0){
    avgeraged_threats <-
      MP_threat_data_subset_ %>% 
      mutate(hum_bi = ifelse(humans > 0 | (!is.na(hum_pri)), 1, 0),
             vehicle_bi = ifelse(vehicles > 0 | (!is.na(vehicle_pri)), 1, 0),
             dogs_bi = ifelse(dogs > 0 | (!is.na(dog_pri)), 1, 0),
             dogs_off_bi = ifelse(dogs_off > 0, 1, 0),
             dogs_on_bi = ifelse(dogs_on > 0, 1, 0),
             p_birds_bi = ifelse(pred_birds > 0, 1, 0),
             gulls_bi = ifelse(gulls > 0, 1, 0),
             hoof_bi = ifelse(hoofed_animals > 0 | (!is.na(hoofed_pri)), 1, 0)) %>%
      dplyr::summarise(
        # fundays = sum(funday),
        hum_avg = mean(humans, na.rm = TRUE),
        vehicles_avg = mean(vehicles, na.rm = TRUE),
        dogs_avg = mean(dogs, na.rm = TRUE),
        dogs_on_avg = mean(dogs_on, na.rm = TRUE),
        dogs_off_avg = mean(dogs_off, na.rm = TRUE),
        hoof_avg = mean(hoofed_animals, na.rm = TRUE),
        p_birds_avg = mean(pred_birds, na.rm = TRUE),
        gulls_avg = mean(gulls, na.rm = TRUE),
        hum_max = max(humans, na.rm = TRUE),
        vehicles_max = max(vehicles, na.rm = TRUE),
        dogs_max = max(dogs, na.rm = TRUE),
        dogs_on_max = max(dogs_on, na.rm = TRUE),
        dogs_off_max = max(dogs_off, na.rm = TRUE),
        hoof_max = max(hoofed_animals, na.rm = TRUE),
        p_birds_max = max(pred_birds, na.rm = TRUE),
        gulls_max = max(gulls, na.rm = TRUE),
        hum_bi = max(hum_bi, na.rm = TRUE),
        vehicle_bi = max(vehicle_bi, na.rm = TRUE),
        dogs_bi = max(dogs_bi, na.rm = TRUE),
        dogs_on_bi = max(dogs_on_bi, na.rm = TRUE),
        dogs_off_bi = max(dogs_off_bi, na.rm = TRUE),
        p_birds_bi = max(p_birds_bi, na.rm = TRUE),
        gulls_bi = max(gulls_bi, na.rm = TRUE),
        hoof_bi = max(hoof_bi, na.rm = TRUE),
        hum_pr = max(hum_pri, na.rm = TRUE),
        vehicle_pr = max(vehicle_pri, na.rm = TRUE),
        dog_pr = max(dog_pri, na.rm = TRUE),
        hoof_pr = max(hoofed_pri, na.rm = TRUE),
        fox_pr = max(fox_pri, na.rm = TRUE),
        n_surveys = n(),
        days_active = days_active,
        halfway = halfway, 
        uncertain_days = uncertain_days)
    
    nest_data_MP_with_threat_data$fundays[i] <- sum(fundays_df$funday)
    nest_data_MP_with_threat_data$hum_a[i] <- avgeraged_threats$hum_avg
    nest_data_MP_with_threat_data$veh_a[i] <- avgeraged_threats$vehicles_avg
    nest_data_MP_with_threat_data$dog_a[i] <- avgeraged_threats$dogs_avg
    nest_data_MP_with_threat_data$don_a[i] <- avgeraged_threats$dogs_on_avg
    nest_data_MP_with_threat_data$dof_a[i] <- avgeraged_threats$dogs_off_avg
    nest_data_MP_with_threat_data$hof_a[i] <- avgeraged_threats$hoof_avg
    nest_data_MP_with_threat_data$pbd_a[i] <- avgeraged_threats$p_birds_avg
    nest_data_MP_with_threat_data$gul_a[i] <- avgeraged_threats$gulls_avg
    
    nest_data_MP_with_threat_data$hum_m[i] <- avgeraged_threats$hum_max
    nest_data_MP_with_threat_data$veh_m[i] <- avgeraged_threats$vehicles_max
    nest_data_MP_with_threat_data$dog_m[i] <- avgeraged_threats$dogs_max
    nest_data_MP_with_threat_data$don_m[i] <- avgeraged_threats$dogs_on_max
    nest_data_MP_with_threat_data$dof_m[i] <- avgeraged_threats$dogs_off_max
    nest_data_MP_with_threat_data$hof_m[i] <- avgeraged_threats$hoof_max
    nest_data_MP_with_threat_data$pbd_m[i] <- avgeraged_threats$p_birds_max
    nest_data_MP_with_threat_data$gul_m[i] <- avgeraged_threats$gulls_max
    
    nest_data_MP_with_threat_data$hum_b[i] <- avgeraged_threats$hum_bi
    nest_data_MP_with_threat_data$veh_b[i] <- avgeraged_threats$vehicle_bi
    nest_data_MP_with_threat_data$dog_b[i] <- avgeraged_threats$dogs_bi
    nest_data_MP_with_threat_data$don_b[i] <- avgeraged_threats$dogs_on_bi
    nest_data_MP_with_threat_data$dof_b[i] <- avgeraged_threats$dogs_off_bi
    nest_data_MP_with_threat_data$pbd_b[i] <- avgeraged_threats$p_birds_bi
    nest_data_MP_with_threat_data$hof_b[i] <- avgeraged_threats$hoof_bi
    nest_data_MP_with_threat_data$gul_b[i] <- avgeraged_threats$gulls_bi
    
    nest_data_MP_with_threat_data$hum_p[i] <- avgeraged_threats$hum_pr
    nest_data_MP_with_threat_data$veh_p[i] <- avgeraged_threats$vehicle_pr
    nest_data_MP_with_threat_data$dog_p[i] <- avgeraged_threats$dog_pr
    nest_data_MP_with_threat_data$hof_p[i] <- avgeraged_threats$hoof_pr
    nest_data_MP_with_threat_data$fox_p[i] <- avgeraged_threats$fox_pr
    
    nest_data_MP_with_threat_data$n_surveys[i] <- avgeraged_threats$n_surveys
    nest_data_MP_with_threat_data$days_active[i] <- avgeraged_threats$days_active
    nest_data_MP_with_threat_data$halfway[i] <- avgeraged_threats$halfway
    nest_data_MP_with_threat_data$uncertain_days[i] <- avgeraged_threats$uncertain_days

    
  }else{
    nest_data_MP_with_threat_data$hum_a[i] <- NA
    nest_data_MP_with_threat_data$veh_a[i] <- NA
    nest_data_MP_with_threat_data$dog_a[i] <- NA
    nest_data_MP_with_threat_data$don_a[i] <- NA
    nest_data_MP_with_threat_data$dof_a[i] <- NA
    nest_data_MP_with_threat_data$hof_a[i] <- NA
    nest_data_MP_with_threat_data$pbd_a[i] <- NA
    nest_data_MP_with_threat_data$gul_a[i] <- NA
    nest_data_MP_with_threat_data$hum_m[i] <- NA
    nest_data_MP_with_threat_data$veh_m[i] <- NA
    nest_data_MP_with_threat_data$dog_m[i] <- NA
    nest_data_MP_with_threat_data$don_m[i] <- NA
    nest_data_MP_with_threat_data$dof_m[i] <- NA
    nest_data_MP_with_threat_data$hof_m[i] <- NA
    nest_data_MP_with_threat_data$pbd_m[i] <- NA
    nest_data_MP_with_threat_data$gul_m[i] <- NA
    nest_data_MP_with_threat_data$hum_b[i] <- NA
    nest_data_MP_with_threat_data$veh_b[i] <- NA
    nest_data_MP_with_threat_data$dog_b[i] <- NA
    nest_data_MP_with_threat_data$don_b[i] <- NA
    nest_data_MP_with_threat_data$dof_b[i] <- NA
    nest_data_MP_with_threat_data$pbd_b[i] <- NA
    nest_data_MP_with_threat_data$gul_b[i] <- NA
    nest_data_MP_with_threat_data$hof_b[i] <- NA
    nest_data_MP_with_threat_data$hum_p[i] <- NA
    nest_data_MP_with_threat_data$veh_p[i] <- NA
    nest_data_MP_with_threat_data$dog_p[i] <- NA
    nest_data_MP_with_threat_data$hof_p[i] <- NA
    nest_data_MP_with_threat_data$fox_p[i] <- NA
    nest_data_MP_with_threat_data$n_surveys[i] <- 0
    nest_data_MP_with_threat_data$days_active[i] <- days_active
    nest_data_MP_with_threat_data$halfway[i] <- halfway
    nest_data_MP_with_threat_data$uncertain_days[i] <- uncertain_days
    nest_data_MP_with_threat_data$fundays[i] <- NA
  }
}
saveRDS(nest_data_MP_with_threat_data, file = "output/nest_data_MP_with_threat_data.rds")

Bellarine / Surf Coast: summarise threat data

Code
nest_data_BSC_with_threat_data <- 
  nest_data_BSC %>% 
  mutate(season_site = paste(season, site, sep = "_")) %>% 
  ####
  
  ####
  filter(season_site %in% sites_intersect_BSC$season_site) %>%
  dplyr::select(season, site, region, nest_ID, 
                FirstFound, LastPresent, LastChecked,
                first_found2, last_alive2, last_checked2,
                management_status, management_level,
                nest_hab, Fate) %>% 
  rename(status = management_status,
         level = management_level) %>% 
  mutate(level = paste0("L", level)) %>% 
  mutate(level = factor(level, 
                        levels = c("L0", "L1", 
                                   "L2", "L3", 
                                   "L4"))) %>% 
  ungroup() %>% 
  mutate(
    hum_a = NA,
    veh_a = NA,
    dog_a = NA,
    don_a = NA,
    dof_a = NA,
    hof_a = NA,
    pbd_a = NA,
    gul_a = NA,
    hum_m = NA,
    veh_m = NA,
    dog_m = NA,
    don_m = NA,
    dof_m = NA,
    hof_m = NA,
    pbd_m = NA,
    gul_m = NA,
    hum_b = NA,
    veh_b = NA,
    dog_b = NA,
    don_b = NA,
    dof_b = NA,
    pbd_b = NA,
    gul_b = NA,
    hof_b = NA,
    hum_p = NA,
    veh_p = NA,
    dog_p = NA,
    hof_p = NA,
    fox_p = NA,
    n_surveys = NA,
    days_active = NA,
    fundays = NA, 
    uncertain_days = NA,
    halfway = NA) %>% 
  filter(FirstFound <= LastPresent & FirstFound <= LastChecked & LastPresent <= LastChecked) %>% 
  filter(first_found2 <= last_alive2 & first_found2 <= last_checked2 & last_alive2 <= last_checked2)

BSC_threat_data_subset <- 
  threat_data__ %>% 
  filter(region == "BSC") %>% 
  mutate(season_site = paste(season, site, sep = "_")) %>% 
  filter(season_site %in% sites_intersect_BSC$season_site) %>%
  ungroup()

for(i in 1:nrow(nest_data_BSC_with_threat_data)){
  FirstFound <- nest_data_BSC_with_threat_data$FirstFound[i]
  LastPresent <- nest_data_BSC_with_threat_data$LastPresent[i]
  LastChecked <- nest_data_BSC_with_threat_data$LastChecked[i]
  FirstFound2 <- nest_data_BSC_with_threat_data$first_found2[i]
  LastPresent2 <- nest_data_BSC_with_threat_data$last_alive2[i]
  LastChecked2 <- nest_data_BSC_with_threat_data$last_checked2[i]
  halfway <- (LastChecked - LastPresent)/2
  days_active <- (LastPresent + halfway) - FirstFound
  uncertain_days <- LastChecked - LastPresent
  site_ <- as.character(nest_data_BSC_with_threat_data$site[i])
  season_ <- as.character(nest_data_BSC_with_threat_data$season[i])
  
  fundays_df <- 
    data.frame(date = seq(from = LastPresent2, to = LastChecked2, 1)) %>% 
    # mutate(weekday = weekdays(dates)) %>% 
    mutate(weekday = factor(as.factor(weekdays(date)), 
                            levels = c("Monday", "Tuesday", "Wednesday", 
                                       "Thursday", "Friday", "Saturday", 
                                       "Sunday")),
           region = "BSC") %>% 
    mutate(year = year(date)) %>% 
    mutate(season = ifelse(month(date) < 6, year - 1, year)) %>% 
    mutate(season = ifelse(month(date) >= 6, 
                           paste0(year, substr(year + 1, 3, 4)), 
                           paste0(season, substr(year, 3, 4)))) %>% 
    left_join(., holidays, by = c("region", "season"), relationship = "many-to-many") %>%
    mutate(holiday = ifelse(date >= start_date & date <= end_date, 1, 0)) %>% 
    group_by(region, season, date) %>% 
    mutate(holiday = max(holiday, na.rm = TRUE)) %>% 
    dplyr::select(-c(event, start_date, end_date)) %>% 
    distinct() %>% 
    ungroup() %>% 
    mutate(day_type = ifelse(holiday == 1 | weekday %in% 
                               c("Saturday", "Sunday"), "funday", "workday")) %>% 
    mutate(funday = ifelse(day_type == "funday", 1, 0))
    
  BSC_threat_data_subset_ <- 
    BSC_threat_data_subset %>% 
    ungroup() %>% 
    # data.frame() %>% 
    # dplyr::filter(as.numeric(obs_date2) >= FirstFound & as.numeric(obs_date2) <= (LastPresent + halfway) & season == season_) %>%
    # dplyr::filter(as.numeric(obs_date2) >= LastPresent & as.numeric(obs_date2) <= (LastPresent + halfway) & season == season_) %>%
    dplyr::filter(as.numeric(obs_date2) >= LastPresent & as.numeric(obs_date2) <= (LastPresent + (LastChecked - LastPresent)) & season == season_) %>%
    dplyr::filter(site == site_)
  
  if(nrow(BSC_threat_data_subset_) > 0){
    avgeraged_threats <-
      BSC_threat_data_subset_ %>% 
      mutate(hum_bi = ifelse(humans > 0 | (!is.na(hum_pri)), 1, 0),
             vehicle_bi = ifelse(vehicles > 0 | (!is.na(vehicle_pri)), 1, 0),
             dogs_bi = ifelse(dogs > 0 | (!is.na(dog_pri)), 1, 0),
             dogs_off_bi = ifelse(dogs_off > 0, 1, 0),
             dogs_on_bi = ifelse(dogs_on > 0, 1, 0),
             p_birds_bi = ifelse(pred_birds > 0, 1, 0),
             gulls_bi = ifelse(gulls > 0, 1, 0),
             hoof_bi = ifelse(hoofed_animals > 0 | (!is.na(hoofed_pri)), 1, 0)) %>%
      dplyr::summarise(
        # fundays = sum(funday),
        hum_avg = mean(humans, na.rm = TRUE),
        vehicles_avg = mean(vehicles, na.rm = TRUE),
        dogs_avg = mean(dogs, na.rm = TRUE),
        dogs_on_avg = mean(dogs_on, na.rm = TRUE),
        dogs_off_avg = mean(dogs_off, na.rm = TRUE),
        hoof_avg = mean(hoofed_animals, na.rm = TRUE),
        p_birds_avg = mean(pred_birds, na.rm = TRUE),
        gulls_avg = mean(gulls, na.rm = TRUE),
        hum_max = max(humans, na.rm = TRUE),
        vehicles_max = max(vehicles, na.rm = TRUE),
        dogs_max = max(dogs, na.rm = TRUE),
        dogs_on_max = max(dogs_on, na.rm = TRUE),
        dogs_off_max = max(dogs_off, na.rm = TRUE),
        hoof_max = max(hoofed_animals, na.rm = TRUE),
        p_birds_max = max(pred_birds, na.rm = TRUE),
        gulls_max = max(gulls, na.rm = TRUE),
        hum_bi = max(hum_bi, na.rm = TRUE),
        vehicle_bi = max(vehicle_bi, na.rm = TRUE),
        dogs_bi = max(dogs_bi, na.rm = TRUE),
        dogs_on_bi = max(dogs_on_bi, na.rm = TRUE),
        dogs_off_bi = max(dogs_off_bi, na.rm = TRUE),
        p_birds_bi = max(p_birds_bi, na.rm = TRUE),
        gulls_bi = max(gulls_bi, na.rm = TRUE),
        hoof_bi = max(hoof_bi, na.rm = TRUE),
        hum_pr = max(hum_pri, na.rm = TRUE),
        vehicle_pr = max(vehicle_pri, na.rm = TRUE),
        dog_pr = max(dog_pri, na.rm = TRUE),
        hoof_pr = max(hoofed_pri, na.rm = TRUE),
        fox_pr = max(fox_pri, na.rm = TRUE),
        n_surveys = n(),
        days_active = days_active,
        halfway = halfway, 
        uncertain_days = uncertain_days)
    
    nest_data_BSC_with_threat_data$fundays[i] <- sum(fundays_df$funday)
    nest_data_BSC_with_threat_data$hum_a[i] <- avgeraged_threats$hum_avg
    nest_data_BSC_with_threat_data$veh_a[i] <- avgeraged_threats$vehicles_avg
    nest_data_BSC_with_threat_data$dog_a[i] <- avgeraged_threats$dogs_avg
    nest_data_BSC_with_threat_data$don_a[i] <- avgeraged_threats$dogs_on_avg
    nest_data_BSC_with_threat_data$dof_a[i] <- avgeraged_threats$dogs_off_avg
    nest_data_BSC_with_threat_data$hof_a[i] <- avgeraged_threats$hoof_avg
    nest_data_BSC_with_threat_data$pbd_a[i] <- avgeraged_threats$p_birds_avg
    nest_data_BSC_with_threat_data$gul_a[i] <- avgeraged_threats$gulls_avg
    
    nest_data_BSC_with_threat_data$hum_m[i] <- avgeraged_threats$hum_max
    nest_data_BSC_with_threat_data$veh_m[i] <- avgeraged_threats$vehicles_max
    nest_data_BSC_with_threat_data$dog_m[i] <- avgeraged_threats$dogs_max
    nest_data_BSC_with_threat_data$don_m[i] <- avgeraged_threats$dogs_on_max
    nest_data_BSC_with_threat_data$dof_m[i] <- avgeraged_threats$dogs_off_max
    nest_data_BSC_with_threat_data$hof_m[i] <- avgeraged_threats$hoof_max
    nest_data_BSC_with_threat_data$pbd_m[i] <- avgeraged_threats$p_birds_max
    nest_data_BSC_with_threat_data$gul_m[i] <- avgeraged_threats$gulls_max
    
    nest_data_BSC_with_threat_data$hum_b[i] <- avgeraged_threats$hum_bi
    nest_data_BSC_with_threat_data$veh_b[i] <- avgeraged_threats$vehicle_bi
    nest_data_BSC_with_threat_data$dog_b[i] <- avgeraged_threats$dogs_bi
    nest_data_BSC_with_threat_data$don_b[i] <- avgeraged_threats$dogs_on_bi
    nest_data_BSC_with_threat_data$dof_b[i] <- avgeraged_threats$dogs_off_bi
    nest_data_BSC_with_threat_data$pbd_b[i] <- avgeraged_threats$p_birds_bi
    nest_data_BSC_with_threat_data$hof_b[i] <- avgeraged_threats$hoof_bi
    nest_data_BSC_with_threat_data$gul_b[i] <- avgeraged_threats$gulls_bi
    
    nest_data_BSC_with_threat_data$hum_p[i] <- avgeraged_threats$hum_pr
    nest_data_BSC_with_threat_data$veh_p[i] <- avgeraged_threats$vehicle_pr
    nest_data_BSC_with_threat_data$dog_p[i] <- avgeraged_threats$dog_pr
    nest_data_BSC_with_threat_data$hof_p[i] <- avgeraged_threats$hoof_pr
    nest_data_BSC_with_threat_data$fox_p[i] <- avgeraged_threats$fox_pr
    
    nest_data_BSC_with_threat_data$n_surveys[i] <- avgeraged_threats$n_surveys
    nest_data_BSC_with_threat_data$days_active[i] <- avgeraged_threats$days_active
    nest_data_BSC_with_threat_data$halfway[i] <- avgeraged_threats$halfway
    nest_data_BSC_with_threat_data$uncertain_days[i] <- avgeraged_threats$uncertain_days

    
  }else{
    nest_data_BSC_with_threat_data$hum_a[i] <- NA
    nest_data_BSC_with_threat_data$veh_a[i] <- NA
    nest_data_BSC_with_threat_data$dog_a[i] <- NA
    nest_data_BSC_with_threat_data$don_a[i] <- NA
    nest_data_BSC_with_threat_data$dof_a[i] <- NA
    nest_data_BSC_with_threat_data$hof_a[i] <- NA
    nest_data_BSC_with_threat_data$pbd_a[i] <- NA
    nest_data_BSC_with_threat_data$gul_a[i] <- NA
    nest_data_BSC_with_threat_data$hum_m[i] <- NA
    nest_data_BSC_with_threat_data$veh_m[i] <- NA
    nest_data_BSC_with_threat_data$dog_m[i] <- NA
    nest_data_BSC_with_threat_data$don_m[i] <- NA
    nest_data_BSC_with_threat_data$dof_m[i] <- NA
    nest_data_BSC_with_threat_data$hof_m[i] <- NA
    nest_data_BSC_with_threat_data$pbd_m[i] <- NA
    nest_data_BSC_with_threat_data$gul_m[i] <- NA
    nest_data_BSC_with_threat_data$hum_b[i] <- NA
    nest_data_BSC_with_threat_data$veh_b[i] <- NA
    nest_data_BSC_with_threat_data$dog_b[i] <- NA
    nest_data_BSC_with_threat_data$don_b[i] <- NA
    nest_data_BSC_with_threat_data$dof_b[i] <- NA
    nest_data_BSC_with_threat_data$pbd_b[i] <- NA
    nest_data_BSC_with_threat_data$gul_b[i] <- NA
    nest_data_BSC_with_threat_data$hof_b[i] <- NA
    nest_data_BSC_with_threat_data$hum_p[i] <- NA
    nest_data_BSC_with_threat_data$veh_p[i] <- NA
    nest_data_BSC_with_threat_data$dog_p[i] <- NA
    nest_data_BSC_with_threat_data$hof_p[i] <- NA
    nest_data_BSC_with_threat_data$fox_p[i] <- NA
    nest_data_BSC_with_threat_data$n_surveys[i] <- 0
    nest_data_BSC_with_threat_data$days_active[i] <- days_active
    nest_data_BSC_with_threat_data$halfway[i] <- halfway
    nest_data_BSC_with_threat_data$uncertain_days[i] <- uncertain_days
    nest_data_BSC_with_threat_data$fundays[i] <- NA
  }
}
saveRDS(nest_data_BSC_with_threat_data, file = "output/nest_data_BSC_with_threat_data.rds")

remove outlier data and those with very infrequent threat surveys (cut off: visited at least once per week)

Code
##### remove outlier data and those with very infrequent threat surveys
nest_data_with_threat_data <-
  bind_rows(nest_data_FP_with_threat_data,
            nest_data_MP_with_threat_data,
            nest_data_BSC_with_threat_data) %>%
  filter(n_surveys > 0) %>% 
  # mutate(dof_b = ifelse(dof_b == 1, "Y", "N")) %>%
  # dplyr::select(-fox_p) %>%
  mutate_at(vars(hum_b, veh_b, dog_b, don_b, dof_b, pbd_b, gul_b, hof_b),
            ~ as.factor(.)) %>% 
  mutate_at(vars(hum_p, veh_p, dog_p, hof_p, fox_p),
            ~ ifelse(is.na(.), 0, .)) 

# nest_data_with_threat_data %>% filter(fundays > 10) %>% dplyr::select(fundays) %>% arrange(desc(fundays))

# nest_data_with_threat_data %>% 
#   filter()

# nest_data_with_threat_data %>% 
#   # filter(fundays <= 25) %>% 
#   ggplot() +
#   geom_histogram(aes(fundays)) +
#   # geom_vline(xintercept = log(10), color = "red") +
#   luke_theme

nest_data_with_threat_data %>% 
  ggplot() +
  geom_histogram(aes(halfway/n_surveys), binwidth = 1) +
  geom_vline(xintercept = 7, color = "red") +
  luke_theme

Code
nest_data_with_threat_data %>% 
  ggplot() +
  geom_histogram(aes(fundays)) +
  geom_vline(xintercept = 7, color = "red") +
  luke_theme

Code
nest_data_with_threat_data_7d <- 
  nest_data_with_threat_data %>% 
  filter(halfway/n_surveys <= 7)

# nest_data_with_threat_data

#### check variable distributions and collinearity ----
# determine the 99% quantile limit for each threat (i.e., to remove outlier data)
threat_data_99_ql_ <- 
  nest_data_with_threat_data_7d %>% 
  summarise_at(c("hum_a", "pbd_a", "gul_a", "veh_a", "dog_a", "don_a", "dof_a", 
                 "hum_m", "pbd_m", "gul_m", "veh_m", "dog_m", "don_m", "dof_m",
                 "hum_p", "veh_p", "dog_p", "hof_p", "fox_p"), 
               ~ quantile(.x, probs = c(0.99)))

nest_data_with_threat_data_7d %>% 
  filter(hum_a <= ceiling(as.numeric(threat_data_99_ql_$hum_a[1]))) %>% 
  ggplot() +
  geom_histogram(aes(hum_a), binwidth = 5) +
  luke_theme +
  xlab("average number of humans counted in territory during active nest")

Code
nest_data_with_threat_data_7d %>% 
  filter(veh_a <= ceiling(as.numeric(threat_data_99_ql_$veh_a[1]))) %>% 
  ggplot() +
  geom_histogram(aes(veh_a), binwidth = 1) +
  luke_theme +
  xlab("average number of vehicles counted in territory during active nest")

Code
nest_data_with_threat_data_7d %>% 
  filter(dog_a <= ceiling(as.numeric(threat_data_99_ql_$dog_a[1]))) %>% 
  ggplot() +
  geom_histogram(aes(dog_a), binwidth = 1) +
  luke_theme +
  xlab("average number of dogs counted in territory during active nest")

Code
nest_data_with_threat_data_7d %>% 
  filter(don_a <= ceiling(as.numeric(threat_data_99_ql_$don_a[1]))) %>% 
  ggplot() +
  geom_histogram(aes(don_a), binwidth = 1) +
  luke_theme +
  xlab("average number of dogs on leashes counted in territory during active nest")

Code
nest_data_with_threat_data_7d %>% 
  filter(dof_a <= ceiling(as.numeric(threat_data_99_ql_$dof_a[1]))) %>% 
  ggplot() +
  geom_histogram(aes(dof_a), binwidth = 1) +
  luke_theme +
  xlab("average number of dogs off leashes counted in territory during active nest")

Code
nest_data_with_threat_data_7d %>% 
  filter(dof_a <= ceiling(as.numeric(threat_data_99_ql_$pbd_a[1]))) %>% 
  ggplot() +
  geom_histogram(aes(pbd_a), binwidth = 1) +
  luke_theme +
  xlab("average number of corvids counted in territory during active nest")

Code
nest_data_with_threat_data_7d %>% 
  filter(dof_a <= ceiling(as.numeric(threat_data_99_ql_$gul_a[1]))) %>% 
  ggplot() +
  geom_histogram(aes(gul_a), binwidth = 1) +
  luke_theme +
  xlab("average number of gulls counted in territory during active nest")

Code
nest_data_with_threat_data_7d %>% 
  filter(hum_m <= ceiling(as.numeric(threat_data_99_ql_$hum_m[1]))) %>% 
  ggplot() +
  geom_histogram(aes(hum_m), binwidth = 1) +
  luke_theme +
  xlab("maximum number of humans counted in territory during active nest")

Code
nest_data_with_threat_data_7d %>% 
  filter(veh_m <= ceiling(as.numeric(threat_data_99_ql_$veh_m[1]))) %>% 
  ggplot() +
  geom_histogram(aes(veh_m), binwidth = 1) +
  luke_theme +
  xlab("maximum number of vehicles counted in territory during active nest")

Code
nest_data_with_threat_data_7d %>% 
  filter(dog_m <= ceiling(as.numeric(threat_data_99_ql_$dog_m[1]))) %>% 
  ggplot() +
  geom_histogram(aes(dog_m), binwidth = 1) +
  luke_theme +
  xlab("maximum number of dogs counted in territory during active nest")

Code
nest_data_with_threat_data_7d %>% 
  filter(don_m <= ceiling(as.numeric(threat_data_99_ql_$don_m[1]))) %>% 
  ggplot() +
  geom_histogram(aes(don_m), binwidth = 1) +
  luke_theme +
  xlab("maximum number of dogs on leashes counted in territory during active nest")

Code
nest_data_with_threat_data_7d %>% 
  filter(dof_m <= ceiling(as.numeric(threat_data_99_ql_$dof_m[1]))) %>% 
  ggplot() +
  geom_histogram(aes(dof_m), binwidth = 1) +
  luke_theme +
  xlab("maximum number of dogs off leashes counted in territory during active nest")

Code
nest_data_with_threat_data_7d %>% 
  filter(dof_a <= ceiling(as.numeric(threat_data_99_ql_$pbd_m[1]))) %>% 
  ggplot() +
  geom_histogram(aes(pbd_m), binwidth = 1) +
  luke_theme +
  xlab("maximum number of corvids counted in territory during active nest")

Code
nest_data_with_threat_data_7d %>% 
  filter(dof_a <= ceiling(as.numeric(threat_data_99_ql_$gul_m[1]))) %>% 
  ggplot() +
  geom_histogram(aes(gul_m), binwidth = 1) +
  luke_theme +
  xlab("maximum number of gulls counted in territory during active nest")

Code
nest_data_with_threat_data_7d %>% 
  filter(hum_p <= ceiling(as.numeric(threat_data_99_ql_$hum_p[1]))) %>% 
  ggplot() +
  geom_histogram(aes(hum_p), binwidth = 1) +
  luke_theme +
  xlab("maximum human print level detected in territory during active nest")

Code
nest_data_with_threat_data_7d %>% 
  filter(veh_p < ceiling(as.numeric(threat_data_99_ql_$veh_p[1]))) %>% 
  ggplot() +
  geom_histogram(aes(veh_p), binwidth = 1) +
  luke_theme +
  xlab("maximum vehicle print level detected in territory during active nest")

Code
nest_data_with_threat_data_7d %>% 
  filter(dog_p <= ceiling(as.numeric(threat_data_99_ql_$dog_p[1]))) %>% 
  ggplot() +
  geom_histogram(aes(dog_p), binwidth = 1) +
  luke_theme +
  xlab("maximum dog print level detected in territory during active nest")

Code
nest_data_with_threat_data_7d %>% 
  filter(hof_p <= ceiling(as.numeric(threat_data_99_ql_$hof_p[1]))) %>% 
  ggplot() +
  geom_histogram(aes(hof_p), binwidth = 1) +
  luke_theme +
  xlab("maximum hooved print level detected in territory during active nest")

Code
nest_data_with_threat_data_7d %>% 
  filter(fox_p <= ceiling(as.numeric(threat_data_99_ql_$fox_p[1]))) %>% 
  ggplot() +
  geom_histogram(aes(fox_p), binwidth = 1) +
  luke_theme +
  xlab("maximum fox print level detected in territory during active nest")

Code
nest_data_with_threat_data_7d_ <- 
  nest_data_with_threat_data_7d %>% 
  filter(fox_p <= ceiling(as.numeric(threat_data_99_ql_$fox_p[1]))) %>% 
  filter(hum_a <= ceiling(as.numeric(threat_data_99_ql_$hum_a[1]))) %>% 
  filter(veh_a <= ceiling(as.numeric(threat_data_99_ql_$veh_a[1]))) %>% 
  filter(dog_a <= ceiling(as.numeric(threat_data_99_ql_$dog_a[1]))) %>% 
  filter(don_a <= ceiling(as.numeric(threat_data_99_ql_$don_a[1]))) %>% 
  filter(dof_a <= ceiling(as.numeric(threat_data_99_ql_$dof_a[1]))) %>% 
  filter(pbd_a <= ceiling(as.numeric(threat_data_99_ql_$pbd_a[1]))) %>% 
  filter(gul_a <= ceiling(as.numeric(threat_data_99_ql_$gul_a[1]))) %>% 
  filter(hum_m <= ceiling(as.numeric(threat_data_99_ql_$hum_m[1]))) %>% 
  filter(veh_m <= ceiling(as.numeric(threat_data_99_ql_$veh_m[1]))) %>% 
  filter(dog_m <= ceiling(as.numeric(threat_data_99_ql_$dog_m[1]))) %>% 
  filter(don_m <= ceiling(as.numeric(threat_data_99_ql_$don_m[1]))) %>% 
  filter(dof_m <= ceiling(as.numeric(threat_data_99_ql_$dof_m[1]))) %>%
  filter(pbd_m <= ceiling(as.numeric(threat_data_99_ql_$pbd_m[1]))) %>% 
  filter(gul_m <= ceiling(as.numeric(threat_data_99_ql_$gul_m[1]))) %>% 
  filter(hum_p <= ceiling(as.numeric(threat_data_99_ql_$hum_p[1]))) %>% 
  filter(veh_p <= ceiling(as.numeric(threat_data_99_ql_$veh_p[1]))) %>% 
  filter(dog_p <= ceiling(as.numeric(threat_data_99_ql_$dog_p[1]))) %>% 
  filter(hof_p <= ceiling(as.numeric(threat_data_99_ql_$hof_p[1]))) %>%
  mutate(fox_p = ifelse(is.infinite(fox_p), 0, fox_p) %>% as.factor())
Code
write.csv(nest_data_with_threat_data_7d_, "data/nest_data_with_threat_data_7d_22082025.csv")

Sample size summary

Number of nests

Code
nest_data_with_threat_data_7d_ %>%
  summarise(n_obs = n())
# A tibble: 1 × 1
  n_obs
  <int>
1  1970

Number of nests at each region

Code
nest_data_with_threat_data_7d_ %>% 
  group_by(region) %>% 
  summarise(n_obs = n())
# A tibble: 3 × 2
  region n_obs
  <chr>  <int>
1 BSC      415
2 FP       653
3 MP       902

Number of nests at each region for each year

Code
nest_data_with_threat_data_7d_ %>% 
  group_by(region, season) %>% 
  summarise(n_obs = n()) %>% 
  pivot_wider(names_from = region, values_from = n_obs) %>% 
  mutate(season = as.numeric(as.character(season))) %>% 
  arrange(season)
# A tibble: 18 × 4
   season   BSC    FP    MP
    <dbl> <int> <int> <int>
 1 200607     8    NA    14
 2 200708     8    NA    19
 3 200809     7    NA     9
 4 200910     7     6    15
 5 201011    11    21    23
 6 201112    24    11    40
 7 201213    17    12    43
 8 201314    10    20    44
 9 201415    15    22    59
10 201516    22    27    71
11 201617    41    40    86
12 201718    38    44    60
13 201819    33    58    56
14 201920    42    69    53
15 202021    48    78    74
16 202122    26    72    83
17 202223    27    67    76
18 202324    31   106    77

Number of nests at each region in each management level

Code
nest_data_with_threat_data_7d_ %>% 
  group_by(region, level) %>% 
  summarise(n_obs = n()) %>% 
  pivot_wider(names_from = region, values_from = n_obs) 
# A tibble: 5 × 4
  level   BSC    FP    MP
  <fct> <int> <int> <int>
1 L0       23   119   167
2 L1       38    49    68
3 L2       66    21    82
4 L3      284   451   583
5 L4        4    13     2

Number of nests at each region in each management status

Code
nest_data_with_threat_data_7d_ %>% 
  group_by(region, status) %>% 
  summarise(n_obs = n()) %>% 
  pivot_wider(names_from = region, values_from = n_obs) 
# A tibble: 2 × 4
  status   BSC    FP    MP
  <fct>  <int> <int> <int>
1 N         59   138   226
2 Y        356   515   676

Nest survival modeling

Prepare data for RMark

Code
nest_data_with_threat_data_7d_ <- 
  read.csv("data/nest_data_with_threat_data_7d_22082025.csv") %>% 
  mutate(season = as.factor(season),
         nest_hab = as.factor(nest_hab),
         status = as.factor(status),
         level = as.factor(level))
Code
occ_FP <- 
  nest_data_with_threat_data_7d_ %>% 
  filter(region == "FP") %>% 
  pull(LastChecked) %>% 
  max(., na.rm = TRUE)

occ_MP <- 
  nest_data_with_threat_data_7d_ %>% 
  filter(region == "MP") %>% 
  pull(LastChecked) %>% 
  max(., na.rm = TRUE)

occ_BSC <- 
  nest_data_with_threat_data_7d_ %>% 
  filter(region == "BSC") %>% 
  pull(LastChecked) %>% 
  max(., na.rm = TRUE)

# create processed RMARK data format as NestSurvival with Year as group
nest_data.processed_FP_5d <- 
  RMark::process.data(nest_data_with_threat_data_7d_ %>% 
                        filter(region == "FP"), 
                      model = "Nest",
                      nocc = occ_FP, groups = c("season", 
                                                "nest_hab", 
                                                "status",
                                                # "site"
                                                # "fox_p", 
                                                "level"))

nest_data.processed_MP_5d <- 
  RMark::process.data(nest_data_with_threat_data_7d_ %>% 
                        filter(region == "MP"), 
                      model = "Nest",
                      nocc = occ_MP, groups = c("season", 
                                                "nest_hab", 
                                                "status",
                                                # "site",
                                                # "fox_p", 
                                                "level"))

nest_data.processed_BSC_5d <- 
  RMark::process.data(nest_data_with_threat_data_7d_ %>% 
                        filter(region == "BSC"), 
                      model = "Nest",
                      nocc = occ_BSC, groups = c("season", 
                                                "nest_hab", 
                                                "status",
                                                # "site",
                                                # "fox_p", 
                                                "level"))

# create the design data
nest_fate.ddl_FP_5d <- RMark::make.design.data(nest_data.processed_FP_5d)
nest_fate.ddl_MP_5d <- RMark::make.design.data(nest_data.processed_MP_5d)
nest_fate.ddl_BSC_5d <- RMark::make.design.data(nest_data.processed_BSC_5d)

# add a new variable to the design data that is the quadratic transformation of
# time
time <- c(0:(occ_FP-1))
Cubic <- time^3
Quadratic <- time^2
quad_time <- data.frame(time, Quadratic, Cubic)
quad_time$time <- c(1:occ_FP)
nest_fate.ddl_FP_5d$S <- 
  RMark::merge_design.covariates(nest_fate.ddl_FP_5d$S, quad_time, 
                                 bygroup = FALSE, bytime = TRUE)

time <- c(0:(occ_MP-1))
Cubic <- time^3
Quadratic <- time^2
quad_time <- data.frame(time, Quadratic, Cubic)
quad_time$time <- c(1:occ_MP)
nest_fate.ddl_MP_5d$S <- 
  RMark::merge_design.covariates(nest_fate.ddl_MP_5d$S, quad_time, 
                                 bygroup = FALSE, bytime = TRUE)

time <- c(0:(occ_BSC-1))
Cubic <- time^3
Quadratic <- time^2
quad_time <- data.frame(time, Quadratic, Cubic)
quad_time$time <- c(1:occ_BSC)
nest_fate.ddl_BSC_5d$S <- 
  RMark::merge_design.covariates(nest_fate.ddl_BSC_5d$S, quad_time, 
                                 bygroup = FALSE, bytime = TRUE)

# nest_fate.ddl$S <- 
#   RMark::merge_design.covariates(nest_fate.ddl$S, data.frame(management_level = c(0, 1, 2, 3, 4)), 
#                                  bygroup = FALSE, bytime = FALSE)

# nest_fate.ddl$S <-
#   inner_join(nest_fate.ddl$S, int_threat_data, by = c("site", "time"))


RMark_data_FP <- 
  list(nest_data.processed = nest_data.processed_FP_5d, 
       nest_fate.ddl = nest_fate.ddl_FP_5d)

RMark_data_MP <- 
  list(nest_data.processed = nest_data.processed_MP_5d, 
       nest_fate.ddl = nest_fate.ddl_MP_5d)

RMark_data_BSC <- 
  list(nest_data.processed = nest_data.processed_BSC_5d, 
       nest_fate.ddl = nest_fate.ddl_BSC_5d)

# RMark_data_FP$nest_data.processed$data %>% summary()
# RMark_data_MP$nest_data.processed$data %>% summary()
# RMark_data_BSC$nest_data.processed$data %>% summary()

Fleurieu Peninsula model selection

Code
nest_survival_FP <- function()
{
  # Specify models to test
  
  # constant daily survival rate (DSR)
  S.dot <- 
    list(formula = ~1)
  
  # fox print status
  # S.fox_p <-
  #   list(formula = ~fox_p)
  
  #### maximum counts of threats
  # max humans detected
  S.hum_m <-
    list(formula = ~hum_m)
  
  # max vehicles detected
  S.veh_m <-
    list(formula = ~veh_m)
  
  # max dogs detected
  S.dog_m <-
    list(formula = ~dog_m)
  
  # max dogs off leash detected
  S.dof_m <-
    list(formula = ~dof_m)
  
  # max corvids detected
  S.pbd_m <-
    list(formula = ~pbd_m)
  
  # max gulls detected
  S.gul_m <-
    list(formula = ~gul_m)
  
  #### interaction of max threat counts and management status 
  # max humans detected
  S.hum_m_x_status <-
    list(formula = ~hum_m * status)
  
  # max vehicles detected and management status
  S.veh_m_x_status <-
    list(formula = ~veh_m * status)
  
  # max dogs detected and management status
  S.dog_m_x_status <-
    list(formula = ~dog_m * status)
  
  # max dogs off leash detected and management status
  S.dof_m_x_status <-
    list(formula = ~dof_m * status)
  
  # max corvids detected and management status
  S.pbd_m_x_status <-
    list(formula = ~pbd_m * status)
  
  # max gulls detected and management status
  S.gul_m_x_status <-
    list(formula = ~gul_m * status)
  
  # specify to run as a nest survival model in program MARK
  cml <- RMark::create.model.list("Nest")
  
  # run model list in MARK. Supress generation of MARK files.
  model.list <- RMark::mark.wrapper(cml,
                                    data = RMark_data_FP$nest_data.processed, 
                                    ddl = RMark_data_FP$nest_fate.ddl,
                                    threads = 4, 
                                    brief = TRUE, 
                                    delete = TRUE) 
  
  # store completed model list
  return(model.list)
}
nest_survival_run_FP <- nest_survival_FP()
nest_survival_run_FP
nest_survival_FP <- 
  list(RMark_data = RMark_data_FP, 
       model_selection = nest_survival_run_FP)
saveRDS(nest_survival_FP, file = "output/nest_survival_FP_threats&status_220825.rds")

Mornington Peninsula model selection

Code
nest_survival_MP <- function()
{
  # Specify models to test
  
  # constant daily survival rate (DSR)
  S.dot <- 
    list(formula = ~1)
  
  # fox print status
  # S.fox_p <-
  #   list(formula = ~fox_p)
  
  #### maximum counts of threats
  # max humans detected
  S.hum_m <-
    list(formula = ~hum_m)
  
  # max vehicles detected
  # S.veh_m <-
  #   list(formula = ~veh_m)
  
  # max dogs detected
  S.dog_m <-
    list(formula = ~dog_m)
  
  # max dogs off leash detected
  S.dof_m <-
    list(formula = ~dof_m)
  
  # max corvids detected
  S.pbd_m <-
    list(formula = ~pbd_m)
  
  # max gulls detected
  S.gul_m <-
    list(formula = ~gul_m)
  
  #### interaction of max threat counts and management status 
  # max humans detected
  S.hum_m_x_status <-
    list(formula = ~hum_m * status)
  
  # max vehicles detected and management status
  # S.veh_m_x_status <-
  #   list(formula = ~veh_m * status)
  
  # max dogs detected and management status
  S.dog_m_x_status <-
    list(formula = ~dog_m * status)
  
  # max dogs off leash detected and management status
  S.dof_m_x_status <-
    list(formula = ~dof_m * status)
  
  # max corvids detected and management status
  S.pbd_m_x_status <-
    list(formula = ~pbd_m * status)
  
  # max gulls detected and management status
  S.gul_m_x_status <-
    list(formula = ~gul_m * status)
  
  # specify to run as a nest survival model in program MARK
  cml <- RMark::create.model.list("Nest")
  
  # run model list in MARK. Supress generation of MARK files.
  model.list <- RMark::mark.wrapper(cml,
                                    data = RMark_data_MP$nest_data.processed, 
                                    ddl = RMark_data_MP$nest_fate.ddl,
                                    threads = 4, 
                                    brief = TRUE, 
                                    delete = TRUE) 
  
  # store completed model list
  return(model.list)
}

nest_survival_run_MP <- nest_survival_MP()
nest_survival_run_MP
nest_survival_MP <- 
  list(RMark_data = RMark_data_MP, 
       model_selection = nest_survival_run_MP)
saveRDS(nest_survival_MP, file = "output/nest_survival_MP_threats&status_220825.rds")

Bellarine / Surf Coast model selection

Code
nest_survival_BSC <- function()
{
  # Specify models to test
  
  # constant daily survival rate (DSR)
  S.dot <- 
    list(formula = ~1)
  
  # fox print status
  # S.fox_p <-
  #   list(formula = ~fox_p)
  
  #### maximum counts of threats
  # max humans detected
  S.hum_m <-
    list(formula = ~hum_m)
  
  # max vehicles detected
  # S.veh_m <-
  #   list(formula = ~veh_m)
  
  # max dogs detected
  S.dog_m <-
    list(formula = ~dog_m)
  
  # max dogs off leash detected
  S.dof_m <-
    list(formula = ~dof_m)
  
  # max corvids detected
  S.pbd_m <-
    list(formula = ~pbd_m)
  
  # max gulls detected
  S.gul_m <-
    list(formula = ~gul_m)
  
  #### interaction of max threat counts and management status 
  # max humans detected
  S.hum_m_x_status <-
    list(formula = ~hum_m * status)
  
  # max vehicles detected and management status
  # S.veh_m_x_status <-
  #   list(formula = ~veh_m * status)
  
  # max dogs detected and management status
  S.dog_m_x_status <-
    list(formula = ~dog_m * status)
  
  # max dogs off leash detected and management status
  S.dof_m_x_status <-
    list(formula = ~dof_m * status)
  
  # max corvids detected and management status
  S.pbd_m_x_status <-
    list(formula = ~pbd_m * status)
  
  # max gulls detected and management status
  S.gul_m_x_status <-
    list(formula = ~gul_m * status)
  
  # specify to run as a nest survival model in program MARK
  cml <- RMark::create.model.list("Nest")
  
  # run model list in MARK. Supress generation of MARK files.
  model.list <- RMark::mark.wrapper(cml,
                                    data = RMark_data_BSC$nest_data.processed, 
                                    ddl = RMark_data_BSC$nest_fate.ddl,
                                    threads = 4, 
                                    brief = TRUE, 
                                    delete = TRUE) 
  
  # store completed model list
  return(model.list)
}

nest_survival_run_BSC <- nest_survival_BSC()
nest_survival_run_BSC
nest_survival_BSC <- 
  list(RMark_data = RMark_data_BSC, 
       model_selection = nest_survival_run_BSC)
saveRDS(nest_survival_BSC, file = "output/nest_survival_BSC_threats&status_220825.rds")

Results

model selection results

Code
nest_survival_FP <- readRDS(file = "output/nest_survival_FP_threats&status_200825.rds")
nest_survival_run_FP <- nest_survival_FP$model_selection

nest_survival_run_FP$model.table %>% 
  dplyr::select(model, npar, DeltaAICc, weight) %>% 
  gt() %>% 
  cols_label(model = html("<i>Fleurieu Peninsula</i>"),
             npar = "K",
             DeltaAICc = "DeltaAICc",
             weight = "weight") %>% 
  fmt_number(columns = DeltaAICc,
             rows = 1:10,
             decimals = 2,
             use_seps = FALSE) %>% 
  fmt_number(columns = weight,
             rows = 1:10,
             decimals = 3,
             use_seps = FALSE) %>% 
  cols_align(align = "left",
             columns = vars(model)) %>% 
  tab_options(row_group.font.weight = "bold",
              row_group.background.color = brewer.pal(9,"Greys")[3],
              table.font.size = 12,
              data_row.padding = 3,
              row_group.padding = 4,
              summary_row.padding = 2,
              column_labels.font.size = 14,
              row_group.font.size = 12,
              table.width = pct(80))
Fleurieu Peninsula K DeltaAICc weight
S(~gul_m * status) 4 0.00 0.517
S(~pbd_m * status) 4 0.37 0.430
S(~dof_m * status) 4 6.05 0.025
S(~veh_m * status) 4 7.13 0.015
S(~dog_m * status) 4 7.66 0.011
S(~hum_m * status) 4 10.99 0.002
S(~pbd_m) 2 70.72 0.000
S(~1) 1 86.94 0.000
S(~dog_m) 2 87.31 0.000
S(~gul_m) 2 88.26 0.000
S(~dof_m) 2 88.38692 0
S(~hum_m) 2 88.93452 0
S(~veh_m) 2 88.93592 0
Code
nest_survival_MP <- readRDS(file = "output/nest_survival_MP_threats&status_200825.rds")
nest_survival_run_MP <- nest_survival_MP$model_selection

nest_survival_run_MP$model.table %>% 
  dplyr::select(model, npar, DeltaAICc, weight) %>% 
  gt() %>% 
  cols_label(model = html("<i>Mornington Peninsula</i>"),
             npar = "K",
             DeltaAICc = "DeltaAICc",
             weight = "weight") %>% 
  fmt_number(columns = DeltaAICc,
             rows = 1:10,
             decimals = 2,
             use_seps = FALSE) %>% 
  fmt_number(columns = weight,
             rows = 1:10,
             decimals = 3,
             use_seps = FALSE) %>% 
  cols_align(align = "left",
             columns = vars(model)) %>% 
  tab_options(row_group.font.weight = "bold",
              row_group.background.color = brewer.pal(9,"Greys")[3],
              table.font.size = 12,
              data_row.padding = 3,
              row_group.padding = 4,
              summary_row.padding = 2,
              column_labels.font.size = 14,
              row_group.font.size = 12,
              table.width = pct(80))
Mornington Peninsula K DeltaAICc weight
S(~hum_m * status) 4 0.00 0.332
S(~gul_m * status) 4 0.09 0.318
S(~dof_m * status) 4 1.79 0.135
S(~pbd_m * status) 4 2.12 0.115
S(~dog_m * status) 4 2.56 0.092
S(~gul_m) 2 9.83 0.002
S(~hum_m) 2 11.06 0.001
S(~1) 1 11.42 0.001
S(~dof_m) 2 11.97 0.001
S(~pbd_m) 2 12.27 0.001
S(~dog_m) 2 12.26978 0.0007196107
Code
nest_survival_BSC <- readRDS(file = "output/nest_survival_BSC_threats&status_200825.rds")
nest_survival_run_BSC <- nest_survival_BSC$model_selection

nest_survival_run_BSC$model.table %>% 
  dplyr::select(model, npar, DeltaAICc, weight) %>% 
  gt() %>% 
  cols_label(model = html("<i>Bellarine / Surf Coast</i>"),
             npar = "K",
             DeltaAICc = "DeltaAICc",
             weight = "weight") %>% 
  fmt_number(columns = DeltaAICc,
             rows = 1:10,
             decimals = 2,
             use_seps = FALSE) %>% 
  fmt_number(columns = weight,
             rows = 1:10,
             decimals = 3,
             use_seps = FALSE) %>% 
  cols_align(align = "left",
             columns = vars(model)) %>% 
  tab_options(row_group.font.weight = "bold",
              row_group.background.color = brewer.pal(9,"Greys")[3],
              table.font.size = 12,
              data_row.padding = 3,
              row_group.padding = 4,
              summary_row.padding = 2,
              column_labels.font.size = 14,
              row_group.font.size = 12,
              table.width = pct(80))
Bellarine / Surf Coast K DeltaAICc weight
S(~gul_m * status) 4 0.00 0.368
S(~pbd_m * status) 4 1.29 0.193
S(~hum_m * status) 4 1.76 0.152
S(~dog_m * status) 4 2.04 0.133
S(~dof_m * status) 4 2.12 0.128
S(~1) 1 8.01 0.007
S(~hum_m) 2 8.55 0.005
S(~pbd_m) 2 9.05 0.004
S(~dof_m) 2 9.15 0.004
S(~gul_m) 2 9.47 0.003
S(~dog_m) 2 9.906445 0.002600438

Effect of weekends and holidays on nest survival

Code
S.fundays <- 
  mark(data = RMark_data_FP$nest_data.processed, 
       ddl = RMark_data_FP$nest_fate.ddl, 
       model = "Nest",
       model.parameters = list("S" = list(formula =  ~ fundays)),
       brief = TRUE, 
       delete = TRUE)

 Model: S(~fundays)  npar= 2  lnl =  2598.3095 AICc = 2602.3108
Code
min.fundays = min(RMark_data_FP$nest_data.processed$data$fundays)
max.fundays = max(RMark_data_FP$nest_data.processed$data$fundays)
fundays.values = seq(from = min.fundays, to = max.fundays, length = 100)
pred.fundays <- 
  covariate.predictions(model = S.fundays, 
                        data = data.frame(fundays = fundays.values),
                        indices = 1)
pred.fundays_FP <- 
  pred.fundays$estimates %>% 
  mutate(region = "FP")

S.fundays <-   
  mark(data = RMark_data_MP$nest_data.processed, 
       ddl = RMark_data_MP$nest_fate.ddl, 
       model = "Nest",
       model.parameters = list("S" = list(formula =  ~ fundays)),
       brief = TRUE, 
       delete = TRUE)

 Model: S(~fundays)  npar= 2  lnl =  3029.8355 AICc = 3033.8365
Code
min.fundays = min(RMark_data_MP$nest_data.processed$data$fundays)
max.fundays = max(RMark_data_MP$nest_data.processed$data$fundays)
fundays.values = seq(from = min.fundays, to = max.fundays, length = 100)
pred.fundays <- 
  covariate.predictions(model = S.fundays, 
                        data = data.frame(fundays = fundays.values),
                        indices = 1)

pred.fundays_MP <- 
  pred.fundays$estimates %>% 
  mutate(region = "MP")

S.fundays <- 
  mark(data = RMark_data_BSC$nest_data.processed, 
       ddl = RMark_data_BSC$nest_fate.ddl, 
       model = "Nest",
       model.parameters = list("S" = list(formula =  ~ fundays)),
       brief = TRUE, 
       delete = TRUE)

 Model: S(~fundays)  npar= 2  lnl =  1486.208 AICc = 1490.2105
Code
min.fundays = min(RMark_data_BSC$nest_data.processed$data$fundays)
max.fundays = max(RMark_data_BSC$nest_data.processed$data$fundays)
fundays.values = seq(from = min.fundays, to = max.fundays, length = 100)
pred.fundays <- 
  covariate.predictions(model = S.fundays, 
                        data = data.frame(fundays = fundays.values),
                        indices = 1)

pred.fundays_BSC <- 
  pred.fundays$estimates %>% 
  mutate(region = "BSC")

pred.fundays <- 
  bind_rows(pred.fundays_FP, pred.fundays_MP, pred.fundays_BSC)

ggplot(pred.fundays, 
       aes(x = covdata, y = estimate, color = region, fill = region)) +
  geom_line(size = 1.5) +
  geom_ribbon(aes(ymin = lcl, ymax = ucl), alpha = 0.2) +
  scale_colour_brewer(palette = "Dark2") +
  scale_fill_brewer(palette = "Dark2") +
  scale_x_continuous(breaks = c(0, 5, 10, 15, 20, 25)) +
  luke_theme +
  theme(legend.position = "none",
        legend.justification = c(1, 0),
        strip.background = element_blank()) +
  xlab("number of weekend days and holidays exposed to") + 
  ylab("estimated daily survival rate (± 95% CI)") +
  ylim(c(0, 1)) +
  facet_grid(. ~ region, labeller = as_labeller(region_names))

Effect of management on mitigating the impact of weekends and holidays on nest survival

Code
S.fundays_status <- 
  mark(data = RMark_data_FP$nest_data.processed, 
       ddl = RMark_data_FP$nest_fate.ddl, 
       model = "Nest",
       model.parameters = list("S" = list(formula =  ~ fundays + status)),
       brief = TRUE, 
       delete = TRUE)

 Model: S(~fundays + status)  npar= 3  lnl =  2547.6255 AICc = 2553.6281
Code
min.fundays_status = min(RMark_data_FP$nest_data.processed$data$fundays)
max.fundays_status = max(RMark_data_FP$nest_data.processed$data$fundays)
fundays.values = seq(from = min.fundays_status, to = max.fundays_status, length = 100)
pred.fundays_status <- 
  covariate.predictions(model = S.fundays_status, 
                        data = data.frame(fundays = fundays.values),
                        indices = c(as.numeric(row.names(filter(RMark_data_FP$nest_fate.ddl$S, status == "N")[1,])), 
                                    as.numeric(row.names(filter(RMark_data_FP$nest_fate.ddl$S, status == "Y")[1,]))))
pred.fundays_status_FP <- 
  pred.fundays_status$estimates %>% 
  mutate(region = "FP",
         status = ifelse(par.index == 1, "N", "Y"))

S.fundays_status <-   
  mark(data = RMark_data_MP$nest_data.processed, 
       ddl = RMark_data_MP$nest_fate.ddl, 
       model = "Nest",
       model.parameters = list("S" = list(formula =  ~ fundays + status)),
       brief = TRUE, 
       delete = TRUE)

 Model: S(~fundays + status)  npar= 3  lnl =  3026.9856 AICc = 3032.9876
Code
min.fundays_status = min(RMark_data_MP$nest_data.processed$data$fundays)
max.fundays_status = max(RMark_data_MP$nest_data.processed$data$fundays)
fundays.values = seq(from = min.fundays_status, to = max.fundays_status, length = 100)
pred.fundays_status <- 
  covariate.predictions(model = S.fundays_status, 
                        data = data.frame(fundays = fundays.values),
                        indices = c(as.numeric(row.names(filter(RMark_data_MP$nest_fate.ddl$S, status == "N")[1,])), 
                                    as.numeric(row.names(filter(RMark_data_MP$nest_fate.ddl$S, status == "Y")[1,]))))
pred.fundays_status_MP <- 
  pred.fundays_status$estimates %>% 
  mutate(region = "MP",
         status = ifelse(par.index == 1, "N", "Y"))

S.fundays_status <- 
  mark(data = RMark_data_BSC$nest_data.processed, 
       ddl = RMark_data_BSC$nest_fate.ddl, 
       model = "Nest",
       model.parameters = list("S" = list(formula =  ~ fundays + status)),
       brief = TRUE, 
       delete = TRUE)

 Model: S(~fundays + status)  npar= 3  lnl =  1444.5921 AICc = 1450.5972
Code
min.fundays_status = min(RMark_data_BSC$nest_data.processed$data$fundays)
max.fundays_status = max(RMark_data_BSC$nest_data.processed$data$fundays)
fundays.values = seq(from = min.fundays_status, to = max.fundays_status, length = 100)
pred.fundays_status <- 
  covariate.predictions(model = S.fundays_status, 
                        data = data.frame(fundays = fundays.values),
                        indices = c(as.numeric(row.names(filter(RMark_data_BSC$nest_fate.ddl$S, status == "N")[1,])), 
                                    as.numeric(row.names(filter(RMark_data_BSC$nest_fate.ddl$S, status == "Y")[1,]))))
pred.fundays_status_BSC <- 
  pred.fundays_status$estimates %>% 
  mutate(region = "BSC",
         status = ifelse(par.index == 1, "N", "Y"))

pred.fundays_status <- 
  bind_rows(pred.fundays_status_FP, pred.fundays_status_MP, pred.fundays_status_BSC)

ggplot(pred.fundays_status, 
       aes(x = covdata, y = estimate, color = status, fill = status)) +
  geom_line(size = 1.5) +
  geom_ribbon(aes(ymin = lcl, ymax = ucl), alpha = 0.2) +
  scale_colour_brewer(palette = "Dark2", 
                      labels = c("No management", "Management")) +
  scale_fill_brewer(palette = "Dark2", 
                      labels = c("No management", "Management")) +
  scale_x_continuous(breaks = c(0, 5, 10, 15, 20, 25)) +
  luke_theme +
  theme(legend.position = c(0.25, 0.1),
        legend.title = element_blank(),
        legend.justification = c(1, 0),
        strip.background = element_blank()) +
  xlab("number of weekend days and holidays exposed to") + 
  ylab("estimated daily survival rate (± 95% CI)") +
  ylim(c(0, 1)) +
  facet_grid(. ~ region, labeller = as_labeller(region_names))

Effect of management Levels on nest survival

Code
S.levels <- 
  mark(data = RMark_data_FP$nest_data.processed, 
       ddl = RMark_data_FP$nest_fate.ddl, 
       model = "Nest",
       model.parameters = list("S" = list(formula =  ~ level)),
       brief = TRUE, 
       delete = TRUE)

 Model: S(~level)  npar= 5  lnl =  2597.462 AICc = 2607.4684
Code
nest_survival_reals_FP_levels <- 
  S.levels$results$real
Groups <- data.frame(
  str_split_fixed(rownames(nest_survival_reals_FP_levels), " ", n = 4))
nest_survival_reals_FP_levels <- cbind(Groups, nest_survival_reals_FP_levels)
nest_survival_reals_FP_levels$rows <-  rownames(nest_survival_reals_FP_levels)
nest_survival_reals_FP_levels$management_level <- 
  as.factor(str_sub(nest_survival_reals_FP_levels$rows, 
                    nchar(nest_survival_reals_FP_levels$rows) - 7, nchar(nest_survival_reals_FP_levels$rows) - 6))
nest_survival_reals_FP_levels <- 
  nest_survival_reals_FP_levels %>% 
  dplyr::select(management_level, estimate, se, lcl, ucl) %>% 
  mutate(region = "FP")
row.names(nest_survival_reals_FP_levels) <- NULL

S.levels <- 
  mark(data = RMark_data_MP$nest_data.processed, 
       ddl = RMark_data_MP$nest_fate.ddl, 
       model = "Nest",
       model.parameters = list("S" = list(formula =  ~ level)),
       brief = TRUE, 
       delete = TRUE)

 Model: S(~level)  npar= 5  lnl =  3189.0882 AICc = 3199.0932
Code
nest_survival_reals_MP_levels <- 
  S.levels$results$real
Groups <- data.frame(
  str_split_fixed(rownames(nest_survival_reals_MP_levels), " ", n = 4))
nest_survival_reals_MP_levels <- cbind(Groups, nest_survival_reals_MP_levels)
nest_survival_reals_MP_levels$rows <-  rownames(nest_survival_reals_MP_levels)
nest_survival_reals_MP_levels$management_level <- 
  as.factor(str_sub(nest_survival_reals_MP_levels$rows, 
                    nchar(nest_survival_reals_MP_levels$rows) - 7, nchar(nest_survival_reals_MP_levels$rows) - 6))
nest_survival_reals_MP_levels <- 
  nest_survival_reals_MP_levels %>% 
  dplyr::select(management_level, estimate, se, lcl, ucl) %>% 
  mutate(region = "MP")
row.names(nest_survival_reals_MP_levels) <- NULL

S.levels <- 
  mark(data = RMark_data_BSC$nest_data.processed, 
       ddl = RMark_data_BSC$nest_fate.ddl, 
       model = "Nest",
       model.parameters = list("S" = list(formula =  ~ level)),
       brief = TRUE, 
       delete = TRUE)

 Model: S(~level)  npar= 5  lnl =  1456.2864 AICc = 1466.299
Code
nest_survival_reals_BSC_levels <- 
  S.levels$results$real
Groups <- data.frame(
  str_split_fixed(rownames(nest_survival_reals_BSC_levels), " ", n = 4))
nest_survival_reals_BSC_levels <- cbind(Groups, nest_survival_reals_BSC_levels)
nest_survival_reals_BSC_levels$rows <-  rownames(nest_survival_reals_BSC_levels)
nest_survival_reals_BSC_levels$management_level <- 
  as.factor(str_sub(nest_survival_reals_BSC_levels$rows, 
                    nchar(nest_survival_reals_BSC_levels$rows) - 7, nchar(nest_survival_reals_BSC_levels$rows) - 6))
nest_survival_reals_BSC_levels <- 
  nest_survival_reals_BSC_levels %>% 
  dplyr::select(management_level, estimate, se, lcl, ucl) %>% 
  mutate(region = "BSC")
row.names(nest_survival_reals_BSC_levels) <- NULL

nest_survival_reals_levels <- 
  bind_rows(nest_survival_reals_FP_levels,
            nest_survival_reals_MP_levels, 
            nest_survival_reals_BSC_levels)

ggplot() +
  geom_line(data = nest_survival_reals_levels, 
            aes(x = management_level, y = estimate, color = region, group = region),
            position = position_dodge(width = 0.5), alpha = 0.2, size = 2) +
  geom_errorbar(data = nest_survival_reals_levels, 
                aes(ymin = lcl, ymax = ucl, 
                    x = management_level, 
                    y = estimate, group = region), position = position_dodge(width = 0.5),
                alpha = 0.5, color = "black", width = 0.3, lwd = 0.5) +
  geom_point(data = nest_survival_reals_levels, 
             aes(x = management_level, y = estimate, fill = region),
             shape = 21, size = 4, position = position_dodge(width = 0.5)) +
  scale_colour_brewer(palette = "Set1") +
  luke_theme +
  theme(legend.position = c(0.8, 0.2),
        legend.justification = c(1, 0),
        strip.background = element_blank()) +
  xlab("management level") + 
  ylab("estimated daily survival rate (± 95% CI)") +
  ylim(c(0.4, 1)) +
  scale_colour_brewer(palette = "Dark2", 
                      name = "Region", 
                      labels = c("Bellarine/Surf Coast", 
                        "Fleurieu Peninsula",
                      "Mornington Peninsula")) +
  scale_fill_brewer(palette = "Dark2", 
                      name = "Region", 
                      labels = c("Bellarine/Surf Coast", 
                        "Fleurieu Peninsula",
                      "Mornington Peninsula"))

Effect of management status on nest survival

Code
S.status <- 
  mark(data = RMark_data_FP$nest_data.processed, 
       ddl = RMark_data_FP$nest_fate.ddl, 
       model = "Nest",
       model.parameters = list("S" = list(formula = ~ status)),
       brief = TRUE, 
       delete = TRUE)

 Model: S(~status)  npar= 2  lnl =  2612.0143 AICc = 2616.0156
Code
nest_survival_reals_FP_status <- 
  S.status$results$real
Groups <- data.frame(
  str_split_fixed(rownames(nest_survival_reals_FP_status), " ", n = 4))
nest_survival_reals_FP_status <- cbind(Groups, nest_survival_reals_FP_status)
nest_survival_reals_FP_status$rows <-  rownames(nest_survival_reals_FP_status)
nest_survival_reals_FP_status$status <- 
  as.factor(str_sub(nest_survival_reals_FP_status$rows, 
                    nchar(nest_survival_reals_FP_status$rows) - 8, nchar(nest_survival_reals_FP_status$rows) - 8))
nest_survival_reals_FP_status <- 
  nest_survival_reals_FP_status %>% 
  dplyr::select(status, estimate, se, lcl, ucl) %>% 
  mutate(region = "FP")
row.names(nest_survival_reals_FP_status) <- NULL

S.status <- 
  mark(data = RMark_data_MP$nest_data.processed, 
       ddl = RMark_data_MP$nest_fate.ddl, 
       model = "Nest",
       model.parameters = list("S" = list(formula =  ~ status)),
       brief = TRUE, 
       delete = TRUE)

 Model: S(~status)  npar= 2  lnl =  3193.7097 AICc = 3197.7107
Code
nest_survival_reals_MP_status <- 
  S.status$results$real
Groups <- data.frame(
  str_split_fixed(rownames(nest_survival_reals_MP_status), " ", n = 4))
nest_survival_reals_MP_status <- cbind(Groups, nest_survival_reals_MP_status)
nest_survival_reals_MP_status$rows <-  rownames(nest_survival_reals_MP_status)
nest_survival_reals_MP_status$status <- 
  as.factor(str_sub(nest_survival_reals_MP_status$rows, 
                    nchar(nest_survival_reals_MP_status$rows) - 8, nchar(nest_survival_reals_MP_status$rows) - 8))
nest_survival_reals_MP_status <- 
  nest_survival_reals_MP_status %>% 
  dplyr::select(status, estimate, se, lcl, ucl) %>% 
  mutate(region = "MP")
row.names(nest_survival_reals_MP_status) <- NULL

S.status <- 
  mark(data = RMark_data_BSC$nest_data.processed, 
       ddl = RMark_data_BSC$nest_fate.ddl, 
       model = "Nest",
       model.parameters = list("S" = list(formula =  ~ status)),
       brief = TRUE, 
       delete = TRUE)

 Model: S(~status)  npar= 2  lnl =  1470.3078 AICc = 1474.3103
Code
nest_survival_reals_BSC_status <- 
  S.status$results$real
Groups <- data.frame(
  str_split_fixed(rownames(nest_survival_reals_BSC_status), " ", n = 4))
nest_survival_reals_BSC_status <- cbind(Groups, nest_survival_reals_BSC_status)
nest_survival_reals_BSC_status$rows <-  rownames(nest_survival_reals_BSC_status)
nest_survival_reals_BSC_status$status <- 
  as.factor(str_sub(nest_survival_reals_BSC_status$rows, 
                    nchar(nest_survival_reals_BSC_status$rows) - 8, nchar(nest_survival_reals_BSC_status$rows) - 8))
nest_survival_reals_BSC_status <- 
  nest_survival_reals_BSC_status %>% 
  dplyr::select(status, estimate, se, lcl, ucl) %>% 
  mutate(region = "BSC")
row.names(nest_survival_reals_BSC_status) <- NULL

nest_survival_reals_status <- 
  bind_rows(nest_survival_reals_FP_status,
            nest_survival_reals_MP_status, 
            nest_survival_reals_BSC_status)

ggplot() +
  geom_line(data = nest_survival_reals_status, 
            aes(x = status, y = estimate, color = region, group = region),
            position = position_dodge(width = 0.5), alpha = 0.2, size = 2) +
  geom_errorbar(data = nest_survival_reals_status, 
                aes(ymin = lcl, ymax = ucl, 
                    x = status, 
                    y = estimate, group = region), position = position_dodge(width = 0.5),
                alpha = 0.5, color = "black", width = 0.3, lwd = 0.5) +
  geom_point(data = nest_survival_reals_status, 
             aes(x = status, y = estimate, fill = region),
             shape = 21, size = 4, position = position_dodge(width = 0.5)) +
  # scale_colour_brewer(palette = "Set1") +
  luke_theme +
  theme(legend.position = c(0.8, 0.2),
        legend.justification = c(1, 0),
        strip.background = element_blank(),
        axis.title.x = element_blank(),
        axis.text.x = element_text(size = 10)) +
  xlab("management level") + 
  ylab("estimated daily survival rate (± 95% CI)") +
  ylim(c(0.4, 1)) +
  scale_colour_brewer(palette = "Dark2", 
                      name = "Region", 
                      labels = c("Bellarine/Surf Coast", 
                        "Fleurieu Peninsula",
                      "Mornington Peninsula")) +
  scale_fill_brewer(palette = "Dark2", 
                      name = "Region", 
                      labels = c("Bellarine/Surf Coast", 
                        "Fleurieu Peninsula",
                      "Mornington Peninsula")) +
  scale_x_discrete(labels = c("No management", "management"))

Effect of Habitat on nest survival

Code
S.habitat <- 
  mark(data = RMark_data_FP$nest_data.processed, 
       ddl = RMark_data_FP$nest_fate.ddl, 
       model = "Nest",
       model.parameters = list("S" = list(formula =  ~ nest_hab)),
       brief = TRUE, 
       delete = TRUE)

 Model: S(~nest_hab)  npar= 4  lnl =  2689.2452 AICc = 2697.2495
Code
nest_survival_reals_FP_habitat <- 
  S.habitat$results$real
Groups <- data.frame(
  str_split_fixed(rownames(nest_survival_reals_FP_habitat), " ", n = 4))
nest_survival_reals_FP_habitat <- cbind(Groups, nest_survival_reals_FP_habitat)
nest_survival_reals_FP_habitat$habitat <- str_extract(nest_survival_reals_FP_habitat$X2, "beach|dune|foredune/face|estuary/spit")
nest_survival_reals_FP_habitat <- 
  nest_survival_reals_FP_habitat %>% 
  dplyr::select(habitat, estimate, se, lcl, ucl) %>% 
  mutate(region = "FP")
row.names(nest_survival_reals_FP_habitat) <- NULL

S.habitat <- 
  mark(data = RMark_data_MP$nest_data.processed, 
       ddl = RMark_data_MP$nest_fate.ddl, 
       model = "Nest",
       model.parameters = list("S" = list(formula =  ~ nest_hab)),
       brief = TRUE, 
       delete = TRUE)

 Model: S(~nest_hab)  npar= 3  lnl =  3207.8569 AICc = 3213.8589
Code
nest_survival_reals_MP_habitat <- 
  S.habitat$results$real
Groups <- data.frame(
  str_split_fixed(rownames(nest_survival_reals_MP_habitat), " ", n = 4))
nest_survival_reals_MP_habitat <- cbind(Groups, nest_survival_reals_MP_habitat)
nest_survival_reals_MP_habitat$habitat <- str_extract(nest_survival_reals_MP_habitat$X2, "beach|dune|foredune/face|estuary/spit")
nest_survival_reals_MP_habitat <- 
  nest_survival_reals_MP_habitat %>% 
  dplyr::select(habitat, estimate, se, lcl, ucl) %>% 
  mutate(region = "MP")
row.names(nest_survival_reals_MP_habitat) <- NULL

S.habitat <- 
  mark(data = RMark_data_BSC$nest_data.processed, 
       ddl = RMark_data_BSC$nest_fate.ddl, 
       model = "Nest",
       model.parameters = list("S" = list(formula =  ~ nest_hab)),
       brief = TRUE, 
       delete = TRUE)

 Model: S(~nest_hab)  npar= 4  lnl =  1797.2033 AICc = 1805.2117
Code
nest_survival_reals_BSC_habitat <- 
  S.habitat$results$real
Groups <- data.frame(
  str_split_fixed(rownames(nest_survival_reals_BSC_habitat), " ", n = 4))
nest_survival_reals_BSC_habitat <- cbind(Groups, nest_survival_reals_BSC_habitat)
nest_survival_reals_BSC_habitat$habitat <- str_extract(nest_survival_reals_BSC_habitat$X2, "beach|dune|foredune/face|estuary/spit")
nest_survival_reals_BSC_habitat <- 
  nest_survival_reals_BSC_habitat %>% 
  dplyr::select(habitat, estimate, se, lcl, ucl) %>% 
  mutate(region = "BSC")
row.names(nest_survival_reals_BSC_habitat) <- NULL

nest_survival_reals_habitat <- 
  bind_rows(nest_survival_reals_FP_habitat,
            nest_survival_reals_MP_habitat, 
            nest_survival_reals_BSC_habitat)

ggplot() +
  geom_errorbar(data = nest_survival_reals_habitat, 
                aes(ymin = lcl, ymax = ucl, 
                    x = habitat, 
                    y = estimate, group = region), position = position_dodge(width = 0.5),
                alpha = 0.5, color = "black", width = 0.3, lwd = 0.5) +
  geom_point(data = nest_survival_reals_habitat, 
             aes(x = habitat, y = estimate, fill = region),
             shape = 21, size = 4, position = position_dodge(width = 0.5)) +
  # scale_colour_brewer(palette = "Set1") +
  luke_theme +
  theme(legend.position = c(0.5, 0.2),
        legend.justification = c(1, 0),
        strip.background = element_blank()) +
  xlab("habitat") + 
  ylab("estimated daily survival rate (± 95% CI)") +
  ylim(c(0.75, 1)) +
  scale_colour_brewer(palette = "Dark2", 
                      name = "Region", 
                      labels = c("Bellarine/Surf Coast", 
                        "Fleurieu Peninsula",
                      "Mornington Peninsula")) +
  scale_fill_brewer(palette = "Dark2", 
                      name = "Region", 
                      labels = c("Bellarine/Surf Coast", 
                        "Fleurieu Peninsula",
                      "Mornington Peninsula"))

Effect of dogs on nest survival (max counted)

Code
S.dog_m <- nest_survival_run_FP[[4]]
min.dog_m = min(RMark_data_FP$nest_data.processed$data$dog_m)
max.dog_m = max(RMark_data_FP$nest_data.processed$data$dog_m)
dog_m.values = seq(from = min.dog_m, to = max.dog_m, length = 100)
pred.dog_m_status <- 
  covariate.predictions(model = S.dog_m, 
                        data = data.frame(dog_m = dog_m.values),
                        indices = c(as.numeric(row.names(filter(RMark_data_FP$nest_fate.ddl$S, status == "N")[1,])), 
                                    as.numeric(row.names(filter(RMark_data_FP$nest_fate.ddl$S, status == "Y")[1,]))))
pred.dog_m_status_FP <- 
  pred.dog_m_status$estimates %>% 
  mutate(region = "FP",
         status = ifelse(par.index == 1, "N", "Y"))

S.dog_m <- nest_survival_run_MP[[4]]
min.dog_m = min(RMark_data_MP$nest_data.processed$data$dog_m)
max.dog_m = max(RMark_data_MP$nest_data.processed$data$dog_m)
dog_m.values = seq(from = min.dog_m, to = max.dog_m, length = 100)
pred.dog_m_status <- 
  covariate.predictions(model = S.dog_m, 
                        data = data.frame(dog_m = dog_m.values),
                        indices = c(as.numeric(row.names(filter(RMark_data_MP$nest_fate.ddl$S, status == "N")[1,])), 
                                    as.numeric(row.names(filter(RMark_data_MP$nest_fate.ddl$S, status == "Y")[1,]))))
pred.dog_m_status_MP <- 
  pred.dog_m_status$estimates %>% 
  mutate(region = "MP",
         status = ifelse(par.index == 1, "N", "Y"))

S.dog_m <- nest_survival_run_BSC[[4]]
min.dog_m = min(RMark_data_BSC$nest_data.processed$data$dog_m)
max.dog_m = max(RMark_data_BSC$nest_data.processed$data$dog_m)
dog_m.values = seq(from = min.dog_m, to = max.dog_m, length = 100)
pred.dog_m_status <- 
  covariate.predictions(model = S.dog_m, 
                        data = data.frame(dog_m = dog_m.values),
                        indices = c(as.numeric(row.names(filter(RMark_data_BSC$nest_fate.ddl$S, status == "N")[1,])), 
                                    as.numeric(row.names(filter(RMark_data_BSC$nest_fate.ddl$S, status == "Y")[1,]))))
pred.dog_m_status_BSC <- 
  pred.dog_m_status$estimates %>% 
  mutate(region = "BSC",
         status = ifelse(par.index == 1, "N", "Y"))

pred.dog_m <- 
  bind_rows(pred.dog_m_status_FP,
            pred.dog_m_status_MP, 
            pred.dog_m_status_BSC)

ggplot(pred.dog_m, 
       aes(x = covdata, y = estimate, color = status, fill = status)) +
  geom_line(size = 1.5) +
  geom_ribbon(aes(ymin = lcl, ymax = ucl), alpha = 0.2) +
  scale_colour_brewer(palette = "Dark2", 
                      labels = c("No management", "Management")) +
  scale_fill_brewer(palette = "Dark2", 
                      labels = c("No management", "Management")) +
  scale_x_continuous(breaks = c(0, 5, 10, 15, 20, 25)) +
  luke_theme +
  theme(legend.position = c(0.25, 0.1),
        legend.title = element_blank(),
        legend.justification = c(1, 0),
        strip.background = element_blank()) +
  xlab("maximum number of dogs exposed to") + 
  ylab("estimated daily survival rate (± 95% CI)") +
  ylim(c(0, 1)) +
  facet_grid(. ~ region, labeller = as_labeller(region_names))

Effect of Dogs off leash on nest survival (max counted)

Code
S.dof_m <- nest_survival_run_FP[[2]]
min.dof_m = min(RMark_data_FP$nest_data.processed$data$dof_m)
max.dof_m = max(RMark_data_FP$nest_data.processed$data$dof_m)
dof_m.values = seq(from = min.dof_m, to = max.dof_m, length = 100)
pred.dof_m_status <- 
  covariate.predictions(model = S.dof_m, 
                        data = data.frame(dof_m = dof_m.values),
                        indices = c(as.numeric(row.names(filter(RMark_data_FP$nest_fate.ddl$S, status == "N")[1,])), 
                                    as.numeric(row.names(filter(RMark_data_FP$nest_fate.ddl$S, status == "Y")[1,]))))
pred.dof_m_status_FP <- 
  pred.dof_m_status$estimates %>% 
  mutate(region = "FP",
         status = ifelse(par.index == 1, "N", "Y"))

S.dof_m <- nest_survival_run_MP[[2]]
min.dof_m = min(RMark_data_MP$nest_data.processed$data$dof_m)
max.dof_m = max(RMark_data_MP$nest_data.processed$data$dof_m)
dof_m.values = seq(from = min.dof_m, to = max.dof_m, length = 100)
pred.dof_m_status <- 
  covariate.predictions(model = S.dof_m, 
                        data = data.frame(dof_m = dof_m.values),
                        indices = c(as.numeric(row.names(filter(RMark_data_MP$nest_fate.ddl$S, status == "N")[1,])), 
                                    as.numeric(row.names(filter(RMark_data_MP$nest_fate.ddl$S, status == "Y")[1,]))))
pred.dof_m_status_MP <- 
  pred.dof_m_status$estimates %>% 
  mutate(region = "MP",
         status = ifelse(par.index == 1, "N", "Y"))

S.dof_m <- nest_survival_run_BSC[[2]]
min.dof_m = min(RMark_data_BSC$nest_data.processed$data$dof_m)
max.dof_m = max(RMark_data_BSC$nest_data.processed$data$dof_m)
dof_m.values = seq(from = min.dof_m, to = max.dof_m, length = 100)
pred.dof_m_status <- 
  covariate.predictions(model = S.dof_m, 
                        data = data.frame(dof_m = dof_m.values),
                        indices = c(as.numeric(row.names(filter(RMark_data_BSC$nest_fate.ddl$S, status == "N")[1,])), 
                                    as.numeric(row.names(filter(RMark_data_BSC$nest_fate.ddl$S, status == "Y")[1,]))))
pred.dof_m_status_BSC <- 
  pred.dof_m_status$estimates %>% 
  mutate(region = "BSC",
         status = ifelse(par.index == 1, "N", "Y"))

pred.dof_m <- 
  bind_rows(pred.dof_m_status_FP,
            pred.dof_m_status_MP, 
            pred.dof_m_status_BSC)

ggplot(pred.dof_m, 
       aes(x = covdata, y = estimate, color = status, fill = status)) +
  geom_line(size = 1.5) +
  geom_ribbon(aes(ymin = lcl, ymax = ucl), alpha = 0.2) +
  scale_colour_brewer(palette = "Dark2", 
                      labels = c("No management", "Management")) +
  scale_fill_brewer(palette = "Dark2", 
                      labels = c("No management", "Management")) +
  scale_x_continuous(breaks = c(0, 5, 10, 15, 20, 25)) +
  luke_theme +
  theme(legend.position = c(0.25, 0.1),
        legend.title = element_blank(),
        legend.justification = c(1, 0),
        strip.background = element_blank()) +
  xlab("maximum number of dogs off leash exposed to") + 
  ylab("estimated daily survival rate (± 95% CI)") +
  ylim(c(0, 1)) +
  facet_grid(. ~ region, labeller = as_labeller(region_names))

Effect of humans on nest survival (max counted)

Code
S.hum_m <- nest_survival_run_FP[[9]]
min.hum_m = min(RMark_data_FP$nest_data.processed$data$hum_m)
max.hum_m = max(RMark_data_FP$nest_data.processed$data$hum_m)
hum_m.values = seq(from = min.hum_m, to = max.hum_m, length = 100)
pred.hum_m_status <- 
  covariate.predictions(model = S.hum_m, 
                        data = data.frame(hum_m = hum_m.values),
                        indices = c(as.numeric(row.names(filter(RMark_data_FP$nest_fate.ddl$S, status == "N")[1,])), 
                                    as.numeric(row.names(filter(RMark_data_FP$nest_fate.ddl$S, status == "Y")[1,]))))
pred.hum_m_status_FP <- 
  pred.hum_m_status$estimates %>% 
  mutate(region = "FP",
         status = ifelse(par.index == 1, "N", "Y"))

S.hum_m <- nest_survival_run_MP[[9]]
min.hum_m = min(RMark_data_MP$nest_data.processed$data$hum_m)
max.hum_m = max(RMark_data_MP$nest_data.processed$data$hum_m)
hum_m.values = seq(from = min.hum_m, to = max.hum_m, length = 100)
pred.hum_m_status <- 
  covariate.predictions(model = S.hum_m, 
                        data = data.frame(hum_m = hum_m.values),
                        indices = c(as.numeric(row.names(filter(RMark_data_MP$nest_fate.ddl$S, status == "N")[1,])), 
                                    as.numeric(row.names(filter(RMark_data_MP$nest_fate.ddl$S, status == "Y")[1,]))))
pred.hum_m_status_MP <- 
  pred.hum_m_status$estimates %>% 
  mutate(region = "MP",
         status = ifelse(par.index == 1, "N", "Y"))

S.hum_m <- nest_survival_run_BSC[[9]]
min.hum_m = min(RMark_data_BSC$nest_data.processed$data$hum_m)
max.hum_m = max(RMark_data_BSC$nest_data.processed$data$hum_m)
hum_m.values = seq(from = min.hum_m, to = max.hum_m, length = 100)
pred.hum_m_status <- 
  covariate.predictions(model = S.hum_m, 
                        data = data.frame(hum_m = hum_m.values),
                        indices = c(as.numeric(row.names(filter(RMark_data_BSC$nest_fate.ddl$S, status == "N")[1,])), 
                                    as.numeric(row.names(filter(RMark_data_BSC$nest_fate.ddl$S, status == "Y")[1,]))))
pred.hum_m_status_BSC <- 
  pred.hum_m_status$estimates %>% 
  mutate(region = "BSC",
         status = ifelse(par.index == 1, "N", "Y"))

pred.hum_m <- 
  bind_rows(pred.hum_m_status_FP,
            pred.hum_m_status_MP, 
            pred.hum_m_status_BSC)

ggplot(pred.hum_m, 
       aes(x = covdata, y = estimate, color = status, fill = status)) +
  geom_line(size = 1.5) +
  geom_ribbon(aes(ymin = lcl, ymax = ucl), alpha = 0.2) +
  scale_colour_brewer(palette = "Dark2", 
                      labels = c("No management", "Management")) +
  scale_fill_brewer(palette = "Dark2", 
                      labels = c("No management", "Management")) +
  scale_x_continuous(breaks = c(0, 10, 20, 30, 40, 50)) +
  luke_theme +
  theme(legend.position = c(0.25, 0.1),
        legend.title = element_blank(),
        legend.justification = c(1, 0),
        strip.background = element_blank()) +
  xlab("maximum number of humans exposed to") + 
  ylab("estimated daily survival rate (± 95% CI)") +
  ylim(c(0, 1)) +
  facet_grid(. ~ region, labeller = as_labeller(region_names))

Effect of corvids on nest survival (max counted)

Code
S.pbd_m <- nest_survival_run_FP[[11]]
min.pbd_m = min(RMark_data_FP$nest_data.processed$data$pbd_m)
max.pbd_m = max(RMark_data_FP$nest_data.processed$data$pbd_m)
pbd_m.values = seq(from = min.pbd_m, to = max.pbd_m, length = 100)
pred.pbd_m_status <- 
  covariate.predictions(model = S.pbd_m, 
                        data = data.frame(pbd_m = pbd_m.values),
                        indices = c(as.numeric(row.names(filter(RMark_data_FP$nest_fate.ddl$S, status == "N")[1,])), 
                                    as.numeric(row.names(filter(RMark_data_FP$nest_fate.ddl$S, status == "Y")[1,]))))
pred.pbd_m_status_FP <- 
  pred.pbd_m_status$estimates %>% 
  mutate(region = "FP",
         status = ifelse(par.index == 1, "N", "Y"))

S.pbd_m <- nest_survival_run_MP[[11]]
min.pbd_m = min(RMark_data_MP$nest_data.processed$data$pbd_m)
max.pbd_m = max(RMark_data_MP$nest_data.processed$data$pbd_m)
pbd_m.values = seq(from = min.pbd_m, to = max.pbd_m, length = 100)
pred.pbd_m_status <- 
  covariate.predictions(model = S.pbd_m, 
                        data = data.frame(pbd_m = pbd_m.values),
                        indices = c(as.numeric(row.names(filter(RMark_data_MP$nest_fate.ddl$S, status == "N")[1,])), 
                                    as.numeric(row.names(filter(RMark_data_MP$nest_fate.ddl$S, status == "Y")[1,]))))
pred.pbd_m_status_MP <- 
  pred.pbd_m_status$estimates %>% 
  mutate(region = "MP",
         status = ifelse(par.index == 1, "N", "Y"))

S.pbd_m <- nest_survival_run_BSC[[11]]
min.pbd_m = min(RMark_data_BSC$nest_data.processed$data$pbd_m)
max.pbd_m = max(RMark_data_BSC$nest_data.processed$data$pbd_m)
pbd_m.values = seq(from = min.pbd_m, to = max.pbd_m, length = 100)
pred.pbd_m_status <- 
  covariate.predictions(model = S.pbd_m, 
                        data = data.frame(pbd_m = pbd_m.values),
                        indices = c(as.numeric(row.names(filter(RMark_data_BSC$nest_fate.ddl$S, status == "N")[1,])), 
                                    as.numeric(row.names(filter(RMark_data_BSC$nest_fate.ddl$S, status == "Y")[1,]))))
pred.pbd_m_status_BSC <- 
  pred.pbd_m_status$estimates %>% 
  mutate(region = "BSC",
         status = ifelse(par.index == 1, "N", "Y"))

pred.pbd_m <- 
  bind_rows(pred.pbd_m_status_FP,
            pred.pbd_m_status_MP, 
            pred.pbd_m_status_BSC)

ggplot(pred.pbd_m, 
       aes(x = covdata, y = estimate, color = status, fill = status)) +
  geom_line(size = 1.5) +
  geom_ribbon(aes(ymin = lcl, ymax = ucl), alpha = 0.2) +
  scale_colour_brewer(palette = "Dark2", 
                      labels = c("No management", "Management")) +
  scale_fill_brewer(palette = "Dark2", 
                      labels = c("No management", "Management")) +
  scale_x_continuous(breaks = c(0, 5, 10, 15, 20, 25)) +
  luke_theme +
  theme(legend.position = c(0.25, 0.1),
        legend.title = element_blank(),
        legend.justification = c(1, 0),
        strip.background = element_blank()) +
  xlab("maximum number of ravens and magpies exposed to") + 
  ylab("estimated daily survival rate (± 95% CI)") +
  ylim(c(0, 1)) +
  facet_grid(. ~ region, labeller = as_labeller(region_names))

Effect of gulls on nest survival (max counted)

Code
S.gul_m <- nest_survival_run_FP[[7]]
min.gul_m = min(RMark_data_FP$nest_data.processed$data$gul_m)
max.gul_m = max(RMark_data_FP$nest_data.processed$data$gul_m)
gul_m.values = seq(from = min.gul_m, to = max.gul_m, length = 100)
pred.gul_m_status <- 
  covariate.predictions(model = S.gul_m, 
                        data = data.frame(gul_m = gul_m.values),
                        indices = c(as.numeric(row.names(filter(RMark_data_FP$nest_fate.ddl$S, status == "N")[1,])), 
                                    as.numeric(row.names(filter(RMark_data_FP$nest_fate.ddl$S, status == "Y")[1,]))))
pred.gul_m_status_FP <- 
  pred.gul_m_status$estimates %>% 
  mutate(region = "FP",
         status = ifelse(par.index == 1, "N", "Y"))

S.gul_m <- nest_survival_run_MP[[7]]
min.gul_m = min(RMark_data_MP$nest_data.processed$data$gul_m)
max.gul_m = max(RMark_data_MP$nest_data.processed$data$gul_m)
gul_m.values = seq(from = min.gul_m, to = max.gul_m, length = 100)
pred.gul_m_status <- 
  covariate.predictions(model = S.gul_m, 
                        data = data.frame(gul_m = gul_m.values),
                        indices = c(as.numeric(row.names(filter(RMark_data_MP$nest_fate.ddl$S, status == "N")[1,])), 
                                    as.numeric(row.names(filter(RMark_data_MP$nest_fate.ddl$S, status == "Y")[1,]))))
pred.gul_m_status_MP <- 
  pred.gul_m_status$estimates %>% 
  mutate(region = "MP",
         status = ifelse(par.index == 1, "N", "Y"))

S.gul_m <- nest_survival_run_BSC[[7]]
min.gul_m = min(RMark_data_BSC$nest_data.processed$data$gul_m)
max.gul_m = max(RMark_data_BSC$nest_data.processed$data$gul_m)
gul_m.values = seq(from = min.gul_m, to = max.gul_m, length = 100)
pred.gul_m_status <- 
  covariate.predictions(model = S.gul_m, 
                        data = data.frame(gul_m = gul_m.values),
                        indices = c(as.numeric(row.names(filter(RMark_data_BSC$nest_fate.ddl$S, status == "N")[1,])), 
                                    as.numeric(row.names(filter(RMark_data_BSC$nest_fate.ddl$S, status == "Y")[1,]))))
pred.gul_m_status_BSC <- 
  pred.gul_m_status$estimates %>% 
  mutate(region = "BSC",
         status = ifelse(par.index == 1, "N", "Y"))

pred.gul_m <- 
  bind_rows(pred.gul_m_status_FP,
            pred.gul_m_status_MP, 
            pred.gul_m_status_BSC)

ggplot(pred.gul_m, 
       aes(x = covdata, y = estimate, color = status, fill = status)) +
  geom_line(size = 1.5) +
  geom_ribbon(aes(ymin = lcl, ymax = ucl), alpha = 0.2) +
  scale_colour_brewer(palette = "Dark2", 
                      labels = c("No management", "Management")) +
  scale_fill_brewer(palette = "Dark2", 
                      labels = c("No management", "Management")) +
  # scale_x_continuous(breaks = c(0, 10, 20, 30, 40, 50, 60, 70)) +
  luke_theme +
  theme(legend.position = c(0.25, 0.1),
        legend.title = element_blank(),
        legend.justification = c(1, 0),
        strip.background = element_blank()) +
  xlab("maximum number of gulls exposed to") + 
  ylab("estimated daily survival rate (± 95% CI)") +
  ylim(c(0, 1)) +
  facet_grid(. ~ region, labeller = as_labeller(region_names))

Effect of Fox activity on nest survival (max print level) (NOT RUN IN MODELS)

Code
# S.fox_prints <- 
#   mark(data = RMark_data_FP$nest_data.processed, 
#        ddl = RMark_data_FP$nest_fate.ddl, 
#        model = "Nest",
#        model.parameters = list("S" = list(formula =  ~ fox_p)),
#        brief = TRUE, 
#        delete = TRUE)
# nest_survival_reals_FP_fox_p <- 
#   S.fox_prints$results$real
# Groups <- data.frame(
#   str_split_fixed(rownames(nest_survival_reals_FP_fox_p), " ", n = 4))
# nest_survival_reals_FP_fox_p <- cbind(Groups, nest_survival_reals_FP_fox_p)
# nest_survival_reals_FP_fox_p$rows <-  rownames(nest_survival_reals_FP_fox_p)
# nest_survival_reals_FP_fox_p$fox_p <- 
#   str_sub(nest_survival_reals_FP_fox_p$rows, 
#           nchar(nest_survival_reals_FP_fox_p$rows) - 6, 
#           nchar(nest_survival_reals_FP_fox_p$rows) - 6)
# nest_survival_reals_FP_fox_p$fox_p <- 
#   as.factor(nest_survival_reals_FP_fox_p$fox_p)
# nest_survival_reals_FP_fox_p <- 
#   nest_survival_reals_FP_fox_p %>% 
#   dplyr::select(fox_p, estimate, se, lcl, ucl) %>% 
#   mutate(region = "FP") %>% 
#   slice(-1)
# row.names(nest_survival_reals_FP_fox_p) <- NULL
# 
# S.fox_prints <- 
#   mark(data = RMark_data_MP$nest_data.processed, 
#        ddl = RMark_data_MP$nest_fate.ddl, 
#        model = "Nest",
#        model.parameters = list("S" = list(formula =  ~ fox_p)),
#        brief = TRUE, 
#        delete = TRUE)
# nest_survival_reals_MP_fox_p <- 
#   S.fox_prints$results$real
# Groups <- data.frame(
#   str_split_fixed(rownames(nest_survival_reals_MP_fox_p), " ", n = 4))
# nest_survival_reals_MP_fox_p <- cbind(Groups, nest_survival_reals_MP_fox_p)
# nest_survival_reals_MP_fox_p$rows <-  rownames(nest_survival_reals_MP_fox_p)
# nest_survival_reals_MP_fox_p$fox_p <- 
#   str_sub(nest_survival_reals_MP_fox_p$rows, 
#           nchar(nest_survival_reals_MP_fox_p$rows) - 6, 
#           nchar(nest_survival_reals_MP_fox_p$rows) - 6)
# nest_survival_reals_MP_fox_p$fox_p <- 
#   as.factor(nest_survival_reals_MP_fox_p$fox_p)
# nest_survival_reals_MP_fox_p <- 
#   nest_survival_reals_MP_fox_p %>% 
#   dplyr::select(fox_p, estimate, se, lcl, ucl) %>% 
#   mutate(region = "MP") %>% 
#   slice(-1)
# row.names(nest_survival_reals_MP_fox_p) <- NULL
# 
# S.fox_prints <- 
#   mark(data = RMark_data_BSC$nest_data.processed, 
#        ddl = RMark_data_BSC$nest_fate.ddl, 
#        model = "Nest",
#        model.parameters = list("S" = list(formula =  ~ fox_p)),
#        brief = TRUE, 
#        delete = TRUE)
# nest_survival_reals_BSC_fox_p <- 
#   S.fox_prints$results$real
# Groups <- data.frame(
#   str_split_fixed(rownames(nest_survival_reals_BSC_fox_p), " ", n = 4))
# nest_survival_reals_BSC_fox_p <- cbind(Groups, nest_survival_reals_BSC_fox_p)
# nest_survival_reals_BSC_fox_p$rows <-  rownames(nest_survival_reals_BSC_fox_p)
# nest_survival_reals_BSC_fox_p$fox_p <- 
#   str_sub(nest_survival_reals_BSC_fox_p$rows, 
#           nchar(nest_survival_reals_BSC_fox_p$rows) - 6, 
#           nchar(nest_survival_reals_BSC_fox_p$rows) - 6) %>% as.factor()
# nest_survival_reals_BSC_fox_p <- 
#   nest_survival_reals_BSC_fox_p %>% 
#   dplyr::select(fox_p, estimate, se, lcl, ucl) %>% 
#   mutate(region = "BSC") %>% 
#   slice(-1)
# row.names(nest_survival_reals_BSC_fox_p) <- NULL
# 
# nest_survival_reals_levels <- 
#   bind_rows(nest_survival_reals_FP_fox_p,
#             nest_survival_reals_MP_fox_p, 
#             nest_survival_reals_BSC_fox_p)
# 
# ggplot() +
#   geom_line(data = nest_survival_reals_levels, 
#             aes(x = fox_p, y = estimate, color = region, group = region),
#             position = position_dodge(width = 0.5), alpha = 0.2, size = 2) +
#   geom_errorbar(data = nest_survival_reals_levels, 
#                 aes(ymin = lcl, ymax = ucl, 
#                     x = fox_p, 
#                     y = estimate, group = region), position = position_dodge(width = 0.5),
#                 alpha = 0.5, color = "black", width = 0.3, lwd = 0.5) +
#   geom_point(data = nest_survival_reals_levels, 
#              aes(x = fox_p, y = estimate, fill = region),
#              shape = 21, size = 4, position = position_dodge(width = 0.5)) +
#   luke_theme +
#   theme(legend.position = c(0.9, 0.1),
#         legend.justification = c(1, 0),
#         strip.background = element_blank()) +
#   xlab("fox prints") + 
#   ylab("estimated daily survival rate (± 95% CI)") +
#   ylim(c(0.55, 1)) +
#   scale_colour_brewer(palette = "Dark2", 
#                       name = "Region", 
#                       labels = #c("Bellarine/Surf Coast", 
#                         # "Fleurieu Peninsula", 
#                       "Mornington Peninsula") +#) +
#   scale_fill_brewer(palette = "Dark2", 
#                       name = "Region", 
#                       labels = #c("Bellarine/Surf Coast", 
#                         # "Fleurieu Peninsula", 
#                       "Mornington Peninsula")

Effect of vehicles on nest survival (max)

Code
S.veh_m <- nest_survival_run_FP[[12]]
min.veh_m = min(RMark_data_FP$nest_data.processed$data$veh_m)
max.veh_m = max(RMark_data_FP$nest_data.processed$data$veh_m)
veh_m.values = seq(from = min.veh_m, to = max.veh_m, length = 100)
pred.veh_m_status <- 
  covariate.predictions(model = S.veh_m, 
                        data = data.frame(veh_m = veh_m.values),
                        indices = c(as.numeric(row.names(filter(RMark_data_FP$nest_fate.ddl$S, status == "N")[1,]))))
pred.veh_m_status_FP <- 
  pred.veh_m_status$estimates %>% 
  mutate(region = "FP")

# S.veh_m <- nest_survival_run_MP[[13]]
# min.veh_m = min(RMark_data_MP$nest_data.processed$data$veh_m)
# max.veh_m = max(RMark_data_MP$nest_data.processed$data$veh_m)
# veh_m.values = seq(from = min.veh_m, to = max.veh_m, length = 100)
# pred.veh_m_status <- 
#   covariate.predictions(model = S.veh_m, 
#                         data = data.frame(veh_m = veh_m.values),
#                         indices = c(as.numeric(row.names(filter(RMark_data_MP$nest_fate.ddl$S, status == "N")[1,]))))
# pred.veh_m_status_MP <- 
#   pred.veh_m_status$estimates %>% 
#   mutate(region = "MP")
# 
# S.veh_m <- nest_survival_run_BSC[[13]]
# min.veh_m = min(RMark_data_BSC$nest_data.processed$data$veh_m)
# max.veh_m = max(RMark_data_BSC$nest_data.processed$data$veh_m)
# veh_m.values = seq(from = min.veh_m, to = max.veh_m, length = 100)
# pred.veh_m_status <- 
#   covariate.predictions(model = S.veh_m, 
#                         data = data.frame(veh_m = veh_m.values),
#                         indices = c(as.numeric(row.names(filter(RMark_data_BSC$nest_fate.ddl$S, status == "N")[1,]))))
# pred.veh_m_status_BSC <- 
#   pred.veh_m_status$estimates %>% 
#   mutate(region = "BSC")
# 
# pred.veh_m <- 
#   bind_rows(pred.veh_m_status_FP, pred.veh_m_status_MP, pred.veh_m_status_BSC)

ggplot(pred.veh_m_status_FP, 
       aes(x = covdata, y = estimate)) +
  geom_line(size = 1.5) +
  geom_ribbon(aes(ymin = lcl, ymax = ucl), alpha = 0.2) +
  scale_colour_brewer(palette = "Dark2", 
                      labels = c("No management", "Management")) +
  scale_fill_brewer(palette = "Dark2", 
                      labels = c("No management", "Management")) +
  scale_x_continuous(breaks = c(0, 1, 2, 3, 4, 5)) +
  luke_theme +
  theme(legend.position = c(0.25, 0.1),
        legend.title = element_blank(),
        legend.justification = c(1, 0),
        strip.background = element_blank()) +
  xlab("maximum number of vehicles exposed to") + 
  ylab("estimated daily survival rate (± 95% CI)") +
  ylim(c(0, 1)) +
  facet_grid(. ~ region, labeller = as_labeller(region_names))

Annual variation in nest survival

Code
S.year <- 
  mark(data = RMark_data_FP$nest_data.processed, 
       ddl = RMark_data_FP$nest_fate.ddl, 
       model = "Nest",
       model.parameters = list("S" = list(formula =  ~ season)),
       brief = TRUE, 
       delete = TRUE)

 Model: S(~season)  npar= 16  lnl =  2682.4887 AICc = 2714.54664631444
Code
nest_survival_reals_FP_year <- 
  S.year$results$real
Groups <- data.frame(
  str_split_fixed(rownames(nest_survival_reals_FP_year), " ", n = 4))
nest_survival_reals_FP_year <- cbind(Groups, nest_survival_reals_FP_year)
nest_survival_reals_FP_year$season <- 
  as.numeric(str_sub(nest_survival_reals_FP_year$X2, 2, 5))
nest_survival_reals_FP_year$season <- paste(nest_survival_reals_FP_year$season, nest_survival_reals_FP_year$season + 1, sep = " - ")
nest_survival_reals_FP_year <- 
  nest_survival_reals_FP_year %>% 
  dplyr::select(season, estimate, se, lcl, ucl) %>% 
  mutate(region = "FP")
row.names(nest_survival_reals_FP_year) <- NULL

S.year <- 
  mark(data = RMark_data_MP$nest_data.processed, 
       ddl = RMark_data_MP$nest_fate.ddl, 
       model = "Nest",
       model.parameters = list("S" = list(formula =  ~ season)),
       brief = TRUE, 
       delete = TRUE)

 Model: S(~season)  npar= 18  lnl =  3202.1658 AICc = 3238.223
Code
nest_survival_reals_MP_year <- 
  S.year$results$real
Groups <- data.frame(
  str_split_fixed(rownames(nest_survival_reals_MP_year), " ", n = 4))
nest_survival_reals_MP_year <- cbind(Groups, nest_survival_reals_MP_year)
nest_survival_reals_MP_year$season <- 
  as.numeric(str_sub(nest_survival_reals_MP_year$X2, 2, 5))
nest_survival_reals_MP_year$season <- paste(nest_survival_reals_MP_year$season, nest_survival_reals_MP_year$season + 1, sep = " - ")
nest_survival_reals_MP_year <- 
  nest_survival_reals_MP_year %>% 
  dplyr::select(season, estimate, se, lcl, ucl) %>% 
  mutate(region = "MP")
row.names(nest_survival_reals_MP_year) <- NULL

S.year <- 
  mark(data = RMark_data_BSC$nest_data.processed, 
       ddl = RMark_data_BSC$nest_fate.ddl, 
       model = "Nest",
       model.parameters = list("S" = list(formula =  ~ season)),
       brief = TRUE, 
       delete = TRUE)

 Model: S(~season)  npar= 18  lnl =  1483.0428 AICc = 1519.18649747899
Code
nest_survival_reals_BSC_year <- 
  S.year$results$real
Groups <- data.frame(
  str_split_fixed(rownames(nest_survival_reals_BSC_year), " ", n = 4))
nest_survival_reals_BSC_year <- cbind(Groups, nest_survival_reals_BSC_year)
nest_survival_reals_BSC_year$season <- 
  as.numeric(str_sub(nest_survival_reals_BSC_year$X2, 2, 5))
nest_survival_reals_BSC_year$season <- paste(nest_survival_reals_BSC_year$season, nest_survival_reals_BSC_year$season + 1, sep = " - ")
nest_survival_reals_BSC_year <- 
  nest_survival_reals_BSC_year %>% 
  dplyr::select(season, estimate, se, lcl, ucl) %>% 
  mutate(region = "BSC")
row.names(nest_survival_reals_BSC_year) <- NULL

nest_survival_reals_year <- 
  bind_rows(nest_survival_reals_FP_year,
            nest_survival_reals_MP_year, 
            nest_survival_reals_BSC_year)

ggplot() +
  geom_line(data = nest_survival_reals_year, 
            aes(x = season, y = estimate, color = region, group = region),
            position = position_dodge(width = 0.5), alpha = 0.2) +
  geom_errorbar(data = nest_survival_reals_year, 
                aes(ymin = lcl, ymax = ucl, 
                    x = season, 
                    y = estimate, group = region), position = position_dodge(width = 0.5),
                alpha = 0.5, color = "black", width = 0.3, lwd = 0.5) +
  geom_point(data = nest_survival_reals_year, 
             aes(x = season, y = estimate, fill = region),
             shape = 21, size = 4, position = position_dodge(width = 0.5)) +
  scale_colour_brewer(palette = "Set1") +
  luke_theme +
  theme(legend.position = "none",
        legend.justification = c(1, 0),
        strip.background = element_blank(),
        axis.text.x = element_text(angle = 45, hjust = 1, vjust = 1)) +
  xlab("season") + 
  ylab("estimated daily survival rate (± 95% CI)") +
  ylim(c(0.7, 1)) +
  scale_colour_brewer(palette = "Dark2") +
  scale_fill_brewer(palette = "Dark2") +
  facet_grid(region ~ ., labeller = as_labeller(region_names))

Variation within years

Code
# Extract estimates of survival from Cubic model with management 
# (non-linear season variation and management effect)
S.season <- 
  mark(data = RMark_data_MP$nest_data.processed, 
       ddl = RMark_data_MP$nest_fate.ddl, 
       model = "Nest",
       model.parameters = list("S" = list(formula =  ~ Time + Quadratic + Cubic)),
       brief = TRUE, 
       delete = TRUE)

 Model: S(~Time + Quadratic + Cubic)  npar= 4  lnl =  3200.3665 AICc = 3208.36984336342
Code
nest_survival_reals_MP_season <- 
  S.season$results$real
Groups <- data.frame(
  str_split_fixed(rownames(nest_survival_reals_MP_season), " ", n = 4))
nest_survival_reals_MP_season <- cbind(Groups, nest_survival_reals_MP_season)
nest_survival_reals_MP_season$day_of_season <- 
  unlist(str_extract_all(nest_survival_reals_MP_season$X4, "\\d+")) %>% unique() %>% as.numeric()
nest_survival_reals_MP_season$region = "MP"

S.season <- 
  mark(data = RMark_data_BSC$nest_data.processed, 
       ddl = RMark_data_BSC$nest_fate.ddl, 
       model = "Nest",
       model.parameters = list("S" = list(formula =  ~ Time + Quadratic + Cubic)),
       brief = TRUE, 
       delete = TRUE)

 Model: S(~Time + Quadratic + Cubic)  npar= 4  lnl =  1487.8666 AICc = 1495.875
Code
nest_survival_reals_BSC_season <- 
  S.season$results$real
Groups <- data.frame(
  str_split_fixed(rownames(nest_survival_reals_BSC_season), " ", n = 4))
nest_survival_reals_BSC_season <- cbind(Groups, nest_survival_reals_BSC_season)
nest_survival_reals_BSC_season$day_of_season <- 
  unlist(str_extract_all(nest_survival_reals_BSC_season$X4, "\\d+")) %>% unique() %>% as.numeric()
nest_survival_reals_BSC_season$region = "BSC"

S.season <- 
  mark(data = RMark_data_FP$nest_data.processed, 
       ddl = RMark_data_FP$nest_fate.ddl, 
       model = "Nest",
       model.parameters = list("S" = list(formula =  ~ Time + Quadratic + Cubic)),
       brief = TRUE, 
       delete = TRUE)

 Model: S(~Time + Quadratic + Cubic)  npar= 4  lnl =  2689.0765 AICc = 2697.0808
Code
nest_survival_reals_FP_season <- 
  S.season$results$real
Groups <- data.frame(
  str_split_fixed(rownames(nest_survival_reals_FP_season), " ", n = 4))
nest_survival_reals_FP_season <- cbind(Groups, nest_survival_reals_FP_season)
nest_survival_reals_FP_season$day_of_season <- 
  unlist(str_extract_all(nest_survival_reals_FP_season$X4, "\\d+")) %>% unique() %>% as.numeric()
nest_survival_reals_FP_season$region = "FP"

nest_survival_reals_season <- 
  bind_rows(
    nest_survival_reals_MP_season, 
            nest_survival_reals_BSC_season,
            nest_survival_reals_FP_season) %>%
  dplyr::select(region, day_of_season, estimate, lcl, ucl)
row.names(nest_survival_reals_season) <- NULL

# FP
dates_for_plot_FP <- 
  data.frame(date = as.Date(min(as.numeric(RMark_data_FP$nest_data.processed$data$FirstFound)):
                              max(max(as.numeric(RMark_data_FP$nest_data.processed$data$LastChecked)), 
                                  max(as.numeric(RMark_data_FP$nest_data.processed$data$LastPresent))), 
                            origin = "2023-01-01") - 180,
             day_of_season = c(0:(max(max(as.numeric(RMark_data_FP$nest_data.processed$data$LastChecked)), 
                                      max(as.numeric(RMark_data_FP$nest_data.processed$data$LastPresent))) - 
                                    min(as.numeric(RMark_data_FP$nest_data.processed$data$FirstFound)))))

nest_survival_reals_dates_FP <- 
  left_join(nest_survival_reals_FP_season, dates_for_plot_FP, by = "day_of_season")

nest_survival_season_plot_FP <- 
  ggplot(data = nest_survival_reals_dates_FP) +
  geom_ribbon(aes(x = date, ymin = lcl, ymax = ucl),
              fill = brewer.pal(8, "Dark2")[c(1)], 
              alpha = 0.3) +
  geom_line(aes(x = date, y = estimate), 
            color = brewer.pal(8, "Dark2")[c(1)],
            size = 1) +
  scale_x_date(date_labels = "%B", 
               expand = c(0.01, 0.01), 
               date_breaks = "1 months") +
  ylab("daily nest survival ± 95% CI") +
  scale_y_continuous(limits = c(0, 1)) +
  luke_theme +
  theme(legend.position = "bottom",
        legend.title = element_blank(),
        panel.grid.major = element_line(colour = "grey70", 
                                        size = 0.15),
        axis.title.x = element_blank(),
        axis.text.x = element_text(angle = 45, 
                                   hjust = 1, 
                                   vjust = 1))

nest_discovery_season_plot_FP <- 
      ggplot(RMark_data_FP$nest_data.processed$data, 
             aes(as.Date(FirstFound, origin = "2023-01-01") - 180,
                               fill = Fate)) +
      geom_histogram(bins = 30,
                     # fill = brewer.pal(8, "Set1")[c(2)], 
                     alpha = 0.5) +
      scale_fill_manual(values = brewer.pal(8, "Set1")[c(2, 1)],
                        labels = c("Failed", "Hatched")) +
      ylab("nests found\nweekly") +
      scale_x_date(date_labels = "%B", 
                   expand = c(0.01, 0.01), 
                   date_breaks = "1 months", limits = c(min(nest_survival_reals_dates_FP$date, na.rm = TRUE), 
                                                        max(nest_survival_reals_dates_FP$date, na.rm = TRUE))) +
      scale_y_continuous(breaks = c(10, 20, 30, 40)) +
      luke_theme +
      theme(legend.position = "none",
            panel.grid.major = element_line(colour = "grey70", 
                                            size = 0.15),
            axis.title.x = element_blank(),
            axis.text.x = element_blank(),
            axis.ticks.x = element_blank())
    
# merge plots together
hooded_plover_nest_plot_FP <- 
  nest_discovery_season_plot_FP / 
  nest_survival_season_plot_FP +
  plot_layout(widths = c(5), 
              heights = unit(c(1, 3), c('in', 'in'))) +
  plot_annotation(tag_levels = 'A', title = "Fleurieu Peninsula")

### MP ----
dates_for_plot_MP <- 
  data.frame(date = as.Date(min(as.numeric(RMark_data_MP$nest_data.processed$data$FirstFound)):
                              max(max(as.numeric(RMark_data_MP$nest_data.processed$data$LastChecked)), 
                                  max(as.numeric(RMark_data_MP$nest_data.processed$data$LastPresent))), 
                            origin = "2023-01-01") - 180,
             day_of_season = c(0:(max(max(as.numeric(RMark_data_MP$nest_data.processed$data$LastChecked)), 
                                      max(as.numeric(RMark_data_MP$nest_data.processed$data$LastPresent))) - 
                                    min(as.numeric(RMark_data_MP$nest_data.processed$data$FirstFound)))))

nest_survival_reals_dates_MP <- 
  left_join(nest_survival_reals_MP_season, dates_for_plot_MP, by = "day_of_season")

nest_survival_season_plot_MP <- 
  ggplot(data = nest_survival_reals_dates_MP) +
  geom_ribbon(aes(x = date, ymin = lcl, ymax = ucl),
              fill = brewer.pal(8, "Dark2")[c(1)], 
              alpha = 0.3) +
  geom_line(aes(x = date, y = estimate), 
            color = brewer.pal(8, "Dark2")[c(1)],
            size = 1) +
  scale_x_date(date_labels = "%B", 
               expand = c(0.01, 0.01), 
               date_breaks = "1 months") +
  ylab("daily nest survival ± 95% CI") +
  scale_y_continuous(limits = c(0, 1)) +
  luke_theme +
  theme(legend.position = "bottom",
        legend.title = element_blank(),
        panel.grid.major = element_line(colour = "grey70", 
                                        size = 0.15),
        axis.title.x = element_blank(),
        axis.text.x = element_text(angle = 45, 
                                   hjust = 1, 
                                   vjust = 1))

nest_discovery_season_plot_MP <- 
      ggplot(RMark_data_MP$nest_data.processed$data, 
             aes(as.Date(FirstFound, origin = "2023-01-01") - 180,
                               fill = Fate)) +
      geom_histogram(bins = 30,
                     # fill = brewer.pal(8, "Set1")[c(2)], 
                     alpha = 0.5) +
      scale_fill_manual(values = brewer.pal(8, "Set1")[c(2, 1)],
                        labels = c("Failed", "Hatched")) +
      ylab("nests found\nweekly") +
      scale_x_date(date_labels = "%B", 
                   expand = c(0.01, 0.01), 
                   date_breaks = "1 months", limits = c(min(nest_survival_reals_dates_MP$date, na.rm = TRUE), 
                                                        max(nest_survival_reals_dates_MP$date, na.rm = TRUE))) +
      scale_y_continuous(breaks = c(10, 20, 30, 40)) +
      luke_theme +
      theme(legend.position = "none",
            panel.grid.major = element_line(colour = "grey70", 
                                            size = 0.15),
            axis.title.x = element_blank(),
            axis.text.x = element_blank(),
            axis.ticks.x = element_blank())
    
# merge plots together
hooded_plover_nest_plot_MP <- 
  nest_discovery_season_plot_MP / 
  nest_survival_season_plot_MP +
  plot_layout(widths = c(5), 
              heights = unit(c(1, 3), c('in', 'in'))) +
  plot_annotation(tag_levels = 'A', title = "Mornington Peninsula")

### BSC ----
dates_for_plot_BSC <- 
  data.frame(date = as.Date(min(as.numeric(RMark_data_BSC$nest_data.processed$data$FirstFound)):
                              max(max(as.numeric(RMark_data_BSC$nest_data.processed$data$LastChecked)), 
                                  max(as.numeric(RMark_data_BSC$nest_data.processed$data$LastPresent))), 
                            origin = "2023-01-01") - 180,
             day_of_season = c(0:(max(max(as.numeric(RMark_data_BSC$nest_data.processed$data$LastChecked)), 
                                      max(as.numeric(RMark_data_BSC$nest_data.processed$data$LastPresent))) - 
                                    min(as.numeric(RMark_data_BSC$nest_data.processed$data$FirstFound)))))

nest_survival_reals_dates_BSC <- 
  left_join(nest_survival_reals_BSC_season, dates_for_plot_BSC, by = "day_of_season")

nest_survival_season_plot_BSC <- 
  ggplot(data = nest_survival_reals_dates_BSC) +
  geom_ribbon(aes(x = date, ymin = lcl, ymax = ucl),
              fill = brewer.pal(8, "Dark2")[c(1)], 
              alpha = 0.3) +
  geom_line(aes(x = date, y = estimate), 
            color = brewer.pal(8, "Dark2")[c(1)],
            size = 1) +
  scale_x_date(date_labels = "%B", 
               expand = c(0.01, 0.01), 
               date_breaks = "1 months", limits = c(min(nest_survival_reals_dates_BSC$date, na.rm = TRUE), 
                                                        max(nest_survival_reals_dates_BSC$date, na.rm = TRUE))) +
  ylab("daily nest survival ± 95% CI") +
  scale_y_continuous(limits = c(0, 1)) +
  luke_theme +
  theme(legend.position = "bottom",
        legend.title = element_blank(),
        panel.grid.major = element_line(colour = "grey70", 
                                        size = 0.15),
        axis.title.x = element_blank(),
        axis.text.x = element_text(angle = 45, 
                                   hjust = 1, 
                                   vjust = 1))

nest_discovery_season_plot_BSC <- 
      ggplot(RMark_data_BSC$nest_data.processed$data, 
             aes(as.Date(FirstFound, origin = "2023-01-01") - 180,
                               fill = Fate)) +
      geom_histogram(bins = 30,
                     # fill = brewer.pal(8, "Set1")[c(2)], 
                     alpha = 0.5) +
      scale_fill_manual(values = brewer.pal(8, "Set1")[c(2, 1)],
                        labels = c("Failed", "Hatched")) +
      ylab("nests found\nweekly") +
      scale_x_date(date_labels = "%B", 
                   expand = c(0.01, 0.01),
                   date_breaks = "1 months", limits = c(min(nest_survival_reals_dates_BSC$date, na.rm = TRUE), 
                                                        max(nest_survival_reals_dates_BSC$date, na.rm = TRUE))) +
      scale_y_continuous(breaks = c(10, 20, 30, 40)) +
      luke_theme +
      theme(legend.position = "none",
            panel.grid.major = element_line(colour = "grey70", 
                                            size = 0.15),
            axis.title.x = element_blank(),
            axis.text.x = element_blank(),
            axis.ticks.x = element_blank())
    
# merge plots together
hooded_plover_nest_plot_BSC <- 
  nest_discovery_season_plot_BSC / 
  nest_survival_season_plot_BSC +
  plot_layout(widths = c(5), 
              heights = unit(c(1, 3), c('in', 'in'))) +
  plot_annotation(tag_levels = 'A', title = "Bellarine / Surf Coast")

hooded_plover_nest_plot_FP

Code
hooded_plover_nest_plot_MP

Code
hooded_plover_nest_plot_BSC

Explore correlations between “Fun days” and the threats

We can see in our model selection of nest survival all three sites that our variable “fun days” (a measure of the number of weekends or holidays a nest is exposed to) was the best at explaining variation in daily nest survival. To interpret this effect, it essentially means that if a nest is initiated on, for example, a Friday right before a long period of consecutive holidays, this nest is expected to have extremely low survival compared to a nest initiated on, for example, a Monday at the early or late part of the season when there are no holidays.

Despite “fun days” having such a strong relationship to daily nest survival, our threat variables (e.g., maximum number of dogs off leash counted, maximum number of humans counted, etc.) all showed little relationship with daily nest survival, which we interpret as a methodological effect: the surveys conducted to quantify specific threats were too infrequent to capture a meaningful measure of the pressure that these threats have on nest survival. To link “Fun days” to the threats, we here do an exploratory relationship between fundays and the threats.

Code
library(lme4)
library(gtsummary)
library(ggeffects)
library(effects)

threat_data__scaled_FP <- 
  threat_data__ %>% 
  mutate(no_fun = ifelse(funday == 0, 1, 0),
                 fun = ifelse(funday == 1, 1, 0)) %>% 
          filter(region == "FP") %>% 
  mutate(humans_s = scale(humans_),
         dogs_s = scale(dogs_),
         pred_birds_s = scale(pred_birds_),
         gull_s = scale(gulls_),
         dogs_off_s = scale(dogs_off_),
         obs_date2_s = scale(obs_date2))

threat_data__scaled_MP <- 
  threat_data__ %>% 
  mutate(no_fun = ifelse(funday == 0, 1, 0),
                 fun = ifelse(funday == 1, 1, 0)) %>% 
          filter(region == "MP") %>% 
  mutate(humans_s = scale(humans_),
         dogs_s = scale(dogs_),
         pred_birds_s = scale(pred_birds_),
         gull_s = scale(gulls_),
         dogs_off_s = scale(dogs_off_),
         obs_date2_s = scale(obs_date2))

threat_data__scaled_BSC <- 
  threat_data__ %>% 
  mutate(no_fun = ifelse(funday == 0, 1, 0),
                 fun = ifelse(funday == 1, 1, 0)) %>% 
          filter(region == "BSC") %>% 
  mutate(humans_s = scale(humans_),
         dogs_s = scale(dogs_),
         pred_birds_s = scale(pred_birds_),
         gull_s = scale(gulls_),
         dogs_off_s = scale(dogs_off_),
         obs_date2_s = scale(obs_date2))

Humans and fun days relationships at the three regions

strong relationship between the number of humans detected and the occurrence of a weekend or a holiday at all 3 regions

Code
humans_fun_day_FP_ <-
  glmer(humans_ ~ 
          poly(obs_date2, 3) + 
          funday + (1 | season) + (1 | site),
        data = threat_data__scaled_FP,
        family = "poisson")

humans_fun_day_MP_ <-
  glmer(humans_ ~ 
          poly(obs_date2, 3) + 
          funday + (1 | season) + (1 | site),
        data = threat_data__scaled_MP,
        family = "poisson")

humans_fun_day_BSC_ <-
  glmer(humans_ ~ 
          poly(obs_date2, 3) + 
          funday + (1 | season) + (1 | site),
        data = threat_data__scaled_BSC,
        family = "poisson")

Fleurieu Peninsula

Code
tbl_regression(humans_fun_day_FP_, intercept = TRUE, 
               label = list(obs_date2 ~ "Date", funday ~ "Weekends & Holidays"))
Characteristic log(IRR) 95% CI p-value
(Intercept) 0.86 0.53, 1.2 <0.001
Date


    poly(obs_date2, 3)1 12 11, 13 <0.001
    poly(obs_date2, 3)2 -16 -17, -15 <0.001
    poly(obs_date2, 3)3 -15 -16, -14 <0.001
Weekends & Holidays 0.56 0.55, 0.57 <0.001
Abbreviations: CI = Confidence Interval, IRR = Incidence Rate Ratio

Mornington Peninsula

Code
tbl_regression(humans_fun_day_MP_, intercept = TRUE, 
               label = list(obs_date2 ~ "Date", funday ~ "Weekends & Holidays"))
Characteristic log(IRR) 95% CI p-value
(Intercept) 0.28 -0.08, 0.64 0.12
Date


    poly(obs_date2, 3)1 15 13, 16 <0.001
    poly(obs_date2, 3)2 -24 -26, -23 <0.001
    poly(obs_date2, 3)3 -5.3 -6.8, -3.8 <0.001
Weekends & Holidays 0.72 0.70, 0.73 <0.001
Abbreviations: CI = Confidence Interval, IRR = Incidence Rate Ratio

Bellarine / Surf Coast

Code
tbl_regression(humans_fun_day_BSC_, intercept = TRUE, 
               label = list(obs_date2 ~ "Date", funday ~ "Weekends & Holidays"))
Characteristic log(IRR) 95% CI p-value
(Intercept) 0.74 0.43, 1.1 <0.001
Date


    poly(obs_date2, 3)1 15 14, 16 <0.001
    poly(obs_date2, 3)2 -4.9 -6.2, -3.6 <0.001
    poly(obs_date2, 3)3 -13 -15, -12 <0.001
Weekends & Holidays 0.77 0.75, 0.80 <0.001
Abbreviations: CI = Confidence Interval, IRR = Incidence Rate Ratio
Code
humans_fun_day_FP__fits <-
  as.data.frame(effect(term = "funday", mod = humans_fun_day_FP_,
                       xlevels = list(funday = seq(min(threat_data__scaled_FP[, "funday"], na.rm = TRUE), max(threat_data__scaled_FP[, "funday"], na.rm = TRUE), 1)))) %>% 
  mutate(region = "FP")

humans_fun_day_MP__fits <-
  as.data.frame(effect(term = "funday", mod = humans_fun_day_MP_,
                       xlevels = list(funday = seq(min(threat_data__scaled_MP[, "funday"], na.rm = TRUE), max(threat_data__scaled_MP[, "funday"], na.rm = TRUE), 1)))) %>% 
  mutate(region = "MP")

humans_fun_day_BSC__fits <-
  as.data.frame(effect(term = "funday", mod = humans_fun_day_BSC_,
                       xlevels = list(funday = seq(min(threat_data__scaled_BSC[, "funday"], na.rm = TRUE), max(threat_data__scaled_BSC[, "funday"], na.rm = TRUE), 1)))) %>% 
  mutate(region = "BSC")

humans_fun_day__fits <- 
  bind_rows(humans_fun_day_FP__fits,
            humans_fun_day_MP__fits, 
            humans_fun_day_BSC__fits) %>%
  mutate(funday = ifelse(funday == 0, "no", "yes"))

row.names(humans_fun_day__fits) <- NULL

ggplot() +
  geom_line(data = humans_fun_day__fits, 
            aes(x = funday, y = fit, color = region, group = region),
            position = position_dodge(width = 0.5), alpha = 0.2, size = 2) +
  geom_errorbar(data = humans_fun_day__fits, 
                aes(ymin = lower, ymax = upper, 
                    x = funday, 
                    y = fit, group = region), position = position_dodge(width = 0.5),
                alpha = 0.5, color = "black", width = 0.3, lwd = 0.5) +
  geom_point(data = humans_fun_day__fits, 
             aes(x = funday, y = fit, fill = region),
             shape = 21, size = 4, position = position_dodge(width = 0.5)) +
  luke_theme +
  theme(legend.position = "top",
        legend.justification = c(1, 0),
        strip.background = element_blank(),
        axis.title.x = element_blank(),
        axis.text.x = element_text(size = 10)) +
  ylab("number of humans detected (± 95% CI)") +
  scale_colour_brewer(palette = "Dark2", 
                      name = "Region", 
                      labels = c("Bellarine/Surf Coast", 
                                 "Fleurieu Peninsula", 
                                 "Mornington Peninsula")) +
  scale_fill_brewer(palette = "Dark2", 
                      name = "Region", 
                      labels = c("Bellarine/Surf Coast", 
                                 "Fleurieu Peninsula", 
                                 "Mornington Peninsula")) +
  scale_x_discrete(labels = c("weekday", "weekend/holiday"))

Dogs and fun days relationships at the three regions

strong relationship between the number of dogs detected and the occurrence of a weekend or a holiday at all 3 regions

Code
dogs_fun_day_FP_ <-
  glmer(dogs_ ~ 
          poly(obs_date2, 3) + 
          funday + (1 | season) + (1 | site),
        data = threat_data__scaled_FP,
        family = "poisson")

dogs_fun_day_MP_ <-
  glmer(dogs_ ~ 
          poly(obs_date2, 3) + 
          funday + (1 | season) + (1 | site),
        data = threat_data__scaled_MP,
        family = "poisson")

dogs_fun_day_BSC_ <-
  glmer(dogs_ ~ 
          poly(obs_date2, 3) + 
          funday + (1 | season) + (1 | site),
        data = threat_data__scaled_BSC,
        family = "poisson")

Fleurieu Peninsula

Code
tbl_regression(dogs_fun_day_FP_, intercept = TRUE, 
               label = list(obs_date2 ~ "Date", funday ~ "Weekends & Holidays"))
Characteristic log(IRR) 95% CI p-value
(Intercept) -0.68 -1.2, -0.20 0.006
Date


    poly(obs_date2, 3)1 4.8 3.3, 6.2 <0.001
    poly(obs_date2, 3)2 -9.7 -11, -8.1 <0.001
    poly(obs_date2, 3)3 -10 -12, -8.9 <0.001
Weekends & Holidays 0.29 0.27, 0.31 <0.001
Abbreviations: CI = Confidence Interval, IRR = Incidence Rate Ratio

Mornington Peninsula

Code
tbl_regression(dogs_fun_day_MP_, intercept = TRUE, 
               label = list(obs_date2 ~ "Date", funday ~ "Weekends & Holidays"))
Characteristic log(IRR) 95% CI p-value
(Intercept) -2.8 -3.4, -2.3 <0.001
Date


    poly(obs_date2, 3)1 -7.4 -13, -1.4 0.016
    poly(obs_date2, 3)2 -5.1 -11, 1.3 0.12
    poly(obs_date2, 3)3 -3.8 -9.7, 2.2 0.2
Weekends & Holidays 0.55 0.47, 0.63 <0.001
Abbreviations: CI = Confidence Interval, IRR = Incidence Rate Ratio

Bellarine / Surf Coast

Code
tbl_regression(dogs_fun_day_BSC_, intercept = TRUE, 
               label = list(obs_date2 ~ "Date", funday ~ "Weekends & Holidays"))
Characteristic log(IRR) 95% CI p-value
(Intercept) -0.17 -0.50, 0.16 0.3
Date


    poly(obs_date2, 3)1 4.0 1.9, 6.0 <0.001
    poly(obs_date2, 3)2 4.9 2.8, 7.1 <0.001
    poly(obs_date2, 3)3 -5.6 -7.7, -3.5 <0.001
Weekends & Holidays 0.56 0.51, 0.61 <0.001
Abbreviations: CI = Confidence Interval, IRR = Incidence Rate Ratio
Code
dogs_fun_day_FP__fits <-
  as.data.frame(effect(term = "funday", mod = dogs_fun_day_FP_,
                       xlevels = list(funday = seq(min(threat_data__scaled_FP[, "funday"], na.rm = TRUE), max(threat_data__scaled_FP[, "funday"], na.rm = TRUE), 1)))) %>% 
  mutate(region = "FP")

dogs_fun_day_MP__fits <-
  as.data.frame(effect(term = "funday", mod = dogs_fun_day_MP_,
                       xlevels = list(funday = seq(min(threat_data__scaled_MP[, "funday"], na.rm = TRUE), max(threat_data__scaled_MP[, "funday"], na.rm = TRUE), 1)))) %>% 
  mutate(region = "MP")

dogs_fun_day_BSC__fits <-
  as.data.frame(effect(term = "funday", mod = dogs_fun_day_BSC_,
                       xlevels = list(funday = seq(min(threat_data__scaled_BSC[, "funday"], na.rm = TRUE), max(threat_data__scaled_BSC[, "funday"], na.rm = TRUE), 1)))) %>% 
  mutate(region = "BSC")

dogs_fun_day__fits <- 
  bind_rows(dogs_fun_day_FP__fits,
            dogs_fun_day_MP__fits, 
            dogs_fun_day_BSC__fits) %>%
  mutate(funday = ifelse(funday == 0, "no", "yes"))

row.names(dogs_fun_day__fits) <- NULL

ggplot() +
  geom_line(data = dogs_fun_day__fits, 
            aes(x = funday, y = fit, color = region, group = region),
            position = position_dodge(width = 0.5), alpha = 0.2, size = 2) +
  geom_errorbar(data = dogs_fun_day__fits, 
                aes(ymin = lower, ymax = upper, 
                    x = funday, 
                    y = fit, group = region), position = position_dodge(width = 0.5),
                alpha = 0.5, color = "black", width = 0.3, lwd = 0.5) +
  geom_point(data = dogs_fun_day__fits, 
             aes(x = funday, y = fit, fill = region),
             shape = 21, size = 4, position = position_dodge(width = 0.5)) +
  luke_theme +
  theme(legend.position = "top",
        legend.justification = c(1, 0),
        strip.background = element_blank(),
        axis.title.x = element_blank(),
        axis.text.x = element_text(size = 10)) +
  ylab("number of dogs detected (± 95% CI)") +
  scale_colour_brewer(palette = "Dark2", 
                      name = "Region", 
                      labels = c("Bellarine/Surf Coast", "Fleurieu Peninsula", "Mornington Peninsula")) +
  scale_fill_brewer(palette = "Dark2",
                    name = "Region", 
                    labels = c("Bellarine/Surf Coast", "Fleurieu Peninsula", "Mornington Peninsula")) +
  scale_x_discrete(labels = c("weekday", "weekend/holiday"))

Dogs off leashes and fun days relationships at the three regions

strong relationship between the number of dogs off leash detected and the occurrence of a weekend or a holiday at all 3 regions

Code
dogs_off_fun_day_FP_ <-
  glmer(dogs_off_ ~ 
          poly(obs_date2, 3) + 
          funday + (1 | season) + (1 | site),
        data = threat_data__scaled_FP,
        family = "poisson")

dogs_off_fun_day_MP_ <-
  glmer(dogs_off_ ~ 
          poly(obs_date2, 3) + 
          funday + (1 | season) + (1 | site),
        data = threat_data__scaled_MP,
        family = "poisson")

dogs_off_fun_day_BSC_ <-
  glmer(dogs_off_ ~ 
          poly(obs_date2, 3) + 
          funday + (1 | season) + (1 | site),
        data = threat_data__scaled_BSC,
        family = "poisson")

Fleurieu Peninsula

Code
tbl_regression(dogs_off_fun_day_FP_, intercept = TRUE, 
               label = list(obs_date2 ~ "Date", funday ~ "Weekends & Holidays"))
Characteristic log(IRR) 95% CI p-value
(Intercept) -1.1 -1.5, -0.60 <0.001
Date


    poly(obs_date2, 3)1 4.4 2.5, 6.2 <0.001
    poly(obs_date2, 3)2 9.0 7.1, 11 <0.001
    poly(obs_date2, 3)3 -9.6 -11, -7.8 <0.001
Weekends & Holidays 0.22 0.19, 0.24 <0.001
Abbreviations: CI = Confidence Interval, IRR = Incidence Rate Ratio

Mornington Peninsula

Code
tbl_regression(dogs_off_fun_day_MP_, intercept = TRUE, 
               label = list(obs_date2 ~ "Date", funday ~ "Weekends & Holidays"))
Characteristic log(IRR) 95% CI p-value
(Intercept) -3.2 -3.9, -2.6 <0.001
Date


    poly(obs_date2, 3)1 -7.4 -14, -0.50 0.036
    poly(obs_date2, 3)2 3.2 -3.4, 9.9 0.3
    poly(obs_date2, 3)3 2.8 -3.9, 9.5 0.4
Weekends & Holidays 0.49 0.39, 0.58 <0.001
Abbreviations: CI = Confidence Interval, IRR = Incidence Rate Ratio

Bellarine / Surf Coast

Code
tbl_regression(dogs_off_fun_day_BSC_, intercept = TRUE, 
               label = list(obs_date2 ~ "Date", funday ~ "Weekends & Holidays"))
Characteristic log(IRR) 95% CI p-value
(Intercept) -0.52 -0.85, -0.19 0.002
Date


    poly(obs_date2, 3)1 -2.8 -5.3, -0.26 0.031
    poly(obs_date2, 3)2 8.2 5.7, 11 <0.001
    poly(obs_date2, 3)3 -0.70 -3.1, 1.7 0.6
Weekends & Holidays 0.44 0.38, 0.50 <0.001
Abbreviations: CI = Confidence Interval, IRR = Incidence Rate Ratio
Code
dogs_off_fun_day_FP__fits <-
  as.data.frame(effect(term = "funday", mod = dogs_off_fun_day_FP_,
                       xlevels = list(funday = seq(min(threat_data__scaled_FP[, "funday"], na.rm = TRUE), max(threat_data__scaled_FP[, "funday"], na.rm = TRUE), 1)))) %>% 
  mutate(region = "FP")

dogs_off_fun_day_MP__fits <-
  as.data.frame(effect(term = "funday", mod = dogs_off_fun_day_MP_,
                       xlevels = list(funday = seq(min(threat_data__scaled_MP[, "funday"], na.rm = TRUE), max(threat_data__scaled_MP[, "funday"], na.rm = TRUE), 1)))) %>% 
  mutate(region = "MP")

dogs_off_fun_day_BSC__fits <-
  as.data.frame(effect(term = "funday", mod = dogs_off_fun_day_BSC_,
                       xlevels = list(funday = seq(min(threat_data__scaled_BSC[, "funday"], na.rm = TRUE), max(threat_data__scaled_BSC[, "funday"], na.rm = TRUE), 1)))) %>% 
  mutate(region = "BSC")

dogs_off_fun_day__fits <- 
  bind_rows(dogs_off_fun_day_FP__fits, 
            dogs_off_fun_day_MP__fits, 
            dogs_off_fun_day_BSC__fits) %>% 
  mutate(funday = ifelse(funday == 0, "no", "yes"))

row.names(dogs_off_fun_day__fits) <- NULL

ggplot() +
  geom_line(data = dogs_off_fun_day__fits, 
            aes(x = funday, y = fit, color = region, group = region),
            position = position_dodge(width = 0.5), alpha = 0.2, size = 2) +
  geom_errorbar(data = dogs_off_fun_day__fits, 
                aes(ymin = lower, ymax = upper, 
                    x = funday, 
                    y = fit, group = region), position = position_dodge(width = 0.5),
                alpha = 0.5, color = "black", width = 0.3, lwd = 0.5) +
  geom_point(data = dogs_off_fun_day__fits, 
             aes(x = funday, y = fit, fill = region),
             shape = 21, size = 4, position = position_dodge(width = 0.5)) +
  luke_theme +
  theme(legend.position = "top",
        legend.justification = c(1, 0),
        strip.background = element_blank(),
        axis.title.x = element_blank(),
        axis.text.x = element_text(size = 10)) +
  ylab("number of dogs off leash detected (± 95% CI)") +
  scale_colour_brewer(palette = "Dark2", 
                      name = "Region", 
                      labels = c("Bellarine/Surf Coast", "Fleurieu Peninsula", "Mornington Peninsula")) +
  scale_fill_brewer(palette = "Dark2",
                    name = "Region", 
                    labels = c("Bellarine/Surf Coast", "Fleurieu Peninsula", "Mornington Peninsula")) +
  scale_x_discrete(labels = c("weekday", "weekend/holiday"))

Ravens and Magpies and fun days relationships at the three regions

weak negative relationship at Fleurieu Peninsula and Mornington Peninsula between the number of corvids detected and the occurrence of a weekend or a holiday

Code
pred_birds_fun_day_FP_ <-
  glmer(pred_birds_ ~ 
          poly(obs_date2, 3) + 
          funday + (1 | season) + (1 | site),
        data = threat_data__scaled_FP,
        family = "poisson")

pred_birds_fun_day_MP_ <-
  glmer(pred_birds_ ~ 
          poly(obs_date2, 3) + 
          funday + (1 | season) + (1 | site),
        data = threat_data__scaled_MP,
        family = "poisson")

pred_birds_fun_day_BSC_ <-
  glmer(pred_birds_ ~ 
          poly(obs_date2, 3) + 
          funday + (1 | season) + (1 | site),
        data = threat_data__scaled_BSC,
        family = "poisson")

Fleurieu Peninsula

Code
tbl_regression(pred_birds_fun_day_FP_, intercept = TRUE, 
               label = list(obs_date2 ~ "Date", funday ~ "Weekends & Holidays"))
Characteristic log(IRR) 95% CI p-value
(Intercept) -1.2 -1.5, -0.89 <0.001
Date


    poly(obs_date2, 3)1 -4.3 -7.9, -0.74 0.018
    poly(obs_date2, 3)2 -28 -32, -25 <0.001
    poly(obs_date2, 3)3 6.9 2.8, 11 <0.001
Weekends & Holidays -0.12 -0.16, -0.08 <0.001
Abbreviations: CI = Confidence Interval, IRR = Incidence Rate Ratio

Mornington Peninsula

Code
tbl_regression(pred_birds_fun_day_MP_, intercept = TRUE, 
               label = list(obs_date2 ~ "Date", funday ~ "Weekends & Holidays"))
Characteristic log(IRR) 95% CI p-value
(Intercept) -1.9 -2.2, -1.5 <0.001
Date


    poly(obs_date2, 3)1 27 22, 32 <0.001
    poly(obs_date2, 3)2 -53 -58, -47 <0.001
    poly(obs_date2, 3)3 19 13, 24 <0.001
Weekends & Holidays -0.25 -0.30, -0.19 <0.001
Abbreviations: CI = Confidence Interval, IRR = Incidence Rate Ratio

Bellarine / Surf Coast

Code
tbl_regression(pred_birds_fun_day_BSC_, intercept = TRUE, 
               label = list(obs_date2 ~ "Date", funday ~ "Weekends & Holidays"))
Characteristic log(IRR) 95% CI p-value
(Intercept) -1.4 -1.7, -1.1 <0.001
Date


    poly(obs_date2, 3)1 0.14 -4.7, 5.0 >0.9
    poly(obs_date2, 3)2 -40 -46, -35 <0.001
    poly(obs_date2, 3)3 7.2 1.4, 13 0.016
Weekends & Holidays -0.08 -0.16, -0.01 0.024
Abbreviations: CI = Confidence Interval, IRR = Incidence Rate Ratio
Code
pred_birds_fun_day_FP__fits <-
  as.data.frame(effect(term = "funday", mod = pred_birds_fun_day_FP_,
                       xlevels = list(funday = seq(min(threat_data__scaled_FP[, "funday"], na.rm = TRUE), max(threat_data__scaled_FP[, "funday"], na.rm = TRUE), 1)))) %>% 
  mutate(region = "FP")

pred_birds_fun_day_MP__fits <-
  as.data.frame(effect(term = "funday", mod = pred_birds_fun_day_MP_,
                       xlevels = list(funday = seq(min(threat_data__scaled_MP[, "funday"], na.rm = TRUE), max(threat_data__scaled_MP[, "funday"], na.rm = TRUE), 1)))) %>% 
  mutate(region = "MP")

pred_birds_fun_day_BSC__fits <-
  as.data.frame(effect(term = "funday", mod = pred_birds_fun_day_BSC_,
                       xlevels = list(funday = seq(min(threat_data__scaled_BSC[, "funday"], na.rm = TRUE), max(threat_data__scaled_BSC[, "funday"], na.rm = TRUE), 1)))) %>% 
  mutate(region = "BSC")

pred_birds_fun_day__fits <- 
  bind_rows(pred_birds_fun_day_FP__fits, 
            pred_birds_fun_day_MP__fits, 
            pred_birds_fun_day_BSC__fits) %>% 
  mutate(funday = ifelse(funday == 0, "no", "yes"))

row.names(pred_birds_fun_day__fits) <- NULL

ggplot() +
  geom_line(data = pred_birds_fun_day__fits, 
            aes(x = funday, y = fit, color = region, group = region),
            position = position_dodge(width = 0.5), alpha = 0.2, size = 2) +
  geom_errorbar(data = pred_birds_fun_day__fits, 
                aes(ymin = lower, ymax = upper, 
                    x = funday, 
                    y = fit, group = region), position = position_dodge(width = 0.5),
                alpha = 0.5, color = "black", width = 0.3, lwd = 0.5) +
  geom_point(data = pred_birds_fun_day__fits, 
             aes(x = funday, y = fit, fill = region),
             shape = 21, size = 4, position = position_dodge(width = 0.5)) +
  luke_theme +
  theme(legend.position = "top",
        legend.justification = c(1, 0),
        strip.background = element_blank(),
        axis.title.x = element_blank(),
        axis.text.x = element_text(size = 10)) +
  ylab("number of magpies and ravens detected (± 95% CI)") +
  scale_colour_brewer(palette = "Dark2", 
                      name = "Region", 
                      labels = c("Bellarine/Surf Coast", "Fleurieu Peninsula", "Mornington Peninsula")) +
  scale_fill_brewer(palette = "Dark2",
                    name = "Region", 
                    labels = c("Bellarine/Surf Coast", "Fleurieu Peninsula", "Mornington Peninsula")) +
  scale_x_discrete(labels = c("weekday", "weekend/holiday"))

Gulls and fun days relationships at the three regions

negative relationship (albeit only significant at Mornington Peninsula) between the number of corvids detected and the occurrence of a weekend or a holiday

Code
gulls_fun_day_FP_ <-
  glmer(gulls_ ~ 
          poly(obs_date2, 3) + 
          funday + (1 | season) + (1 | site),
        data = threat_data__scaled_FP,
        family = "poisson")

gulls_fun_day_MP_ <-
  glmer(gulls_ ~ 
          poly(obs_date2, 3) + 
          funday + (1 | season) + (1 | site),
        data = threat_data__scaled_MP,
        family = "poisson")

gulls_fun_day_BSC_ <-
  glmer(gulls_ ~ 
          poly(obs_date2, 3) + 
          funday + (1 | season) + (1 | site),
        data = threat_data__scaled_BSC,
        family = "poisson")

Fleurieu Peninsula

Code
tbl_regression(gulls_fun_day_FP_, intercept = TRUE, 
               label = list(obs_date2 ~ "Date", funday ~ "Weekends & Holidays"))
Characteristic log(IRR) 95% CI p-value
(Intercept) -1.0 -1.4, -0.70 <0.001
Date


    poly(obs_date2, 3)1 4.6 1.5, 7.7 0.004
    poly(obs_date2, 3)2 -32 -36, -29 <0.001
    poly(obs_date2, 3)3 3.0 -0.19, 6.2 0.065
Weekends & Holidays -0.10 -0.13, -0.06 <0.001
Abbreviations: CI = Confidence Interval, IRR = Incidence Rate Ratio

Mornington Peninsula

Code
tbl_regression(gulls_fun_day_MP_, intercept = TRUE, 
               label = list(obs_date2 ~ "Date", funday ~ "Weekends & Holidays"))
Characteristic log(IRR) 95% CI p-value
(Intercept) -1.7 -2.1, -1.3 <0.001
Date


    poly(obs_date2, 3)1 33 28, 39 <0.001
    poly(obs_date2, 3)2 -62 -67, -57 <0.001
    poly(obs_date2, 3)3 19 14, 25 <0.001
Weekends & Holidays -0.23 -0.28, -0.18 <0.001
Abbreviations: CI = Confidence Interval, IRR = Incidence Rate Ratio

Bellarine / Surf Coast

Code
tbl_regression(gulls_fun_day_BSC_, intercept = TRUE, 
               label = list(obs_date2 ~ "Date", funday ~ "Weekends & Holidays"))
Characteristic log(IRR) 95% CI p-value
(Intercept) -1.1 -1.5, -0.73 <0.001
Date


    poly(obs_date2, 3)1 3.4 -0.67, 7.5 0.10
    poly(obs_date2, 3)2 -47 -52, -42 <0.001
    poly(obs_date2, 3)3 -4.5 -9.7, 0.63 0.085
Weekends & Holidays -0.10 -0.16, -0.05 <0.001
Abbreviations: CI = Confidence Interval, IRR = Incidence Rate Ratio
Code
gulls_fun_day_FP__fits <-
  as.data.frame(effect(term = "funday", mod = gulls_fun_day_FP_,
                       xlevels = list(funday = seq(min(threat_data__scaled_FP[, "funday"], na.rm = TRUE), max(threat_data__scaled_FP[, "funday"], na.rm = TRUE), 1)))) %>% 
  mutate(region = "FP")

gulls_fun_day_MP__fits <-
  as.data.frame(effect(term = "funday", mod = gulls_fun_day_MP_,
                       xlevels = list(funday = seq(min(threat_data__scaled_MP[, "funday"], na.rm = TRUE), max(threat_data__scaled_MP[, "funday"], na.rm = TRUE), 1)))) %>% 
  mutate(region = "MP")

gulls_fun_day_BSC__fits <-
  as.data.frame(effect(term = "funday", mod = gulls_fun_day_BSC_,
                       xlevels = list(funday = seq(min(threat_data__scaled_BSC[, "funday"], na.rm = TRUE), max(threat_data__scaled_BSC[, "funday"], na.rm = TRUE), 1)))) %>% 
  mutate(region = "BSC")

gulls_fun_day__fits <- 
  bind_rows(gulls_fun_day_FP__fits, 
            gulls_fun_day_MP__fits, 
            gulls_fun_day_BSC__fits) %>% 
  mutate(funday = ifelse(funday == 0, "no", "yes"))

row.names(gulls_fun_day__fits) <- NULL

ggplot() +
  geom_line(data = gulls_fun_day__fits, 
            aes(x = funday, y = fit, color = region, group = region),
            position = position_dodge(width = 0.5), alpha = 0.2, size = 2) +
  geom_errorbar(data = gulls_fun_day__fits, 
                aes(ymin = lower, ymax = upper, 
                    x = funday, 
                    y = fit, group = region), position = position_dodge(width = 0.5),
                alpha = 0.5, color = "black", width = 0.3, lwd = 0.5) +
  geom_point(data = gulls_fun_day__fits, 
             aes(x = funday, y = fit, fill = region),
             shape = 21, size = 4, position = position_dodge(width = 0.5)) +
  luke_theme +
  theme(legend.position = "top",
        legend.justification = c(1, 0),
        strip.background = element_blank(),
        axis.title.x = element_blank(),
        axis.text.x = element_text(size = 10)) +
  ylab("number of gulls detected (± 95% CI)") +
  scale_colour_brewer(palette = "Dark2", 
                      name = "Region", 
                      labels = c("Bellarine/Surf Coast", "Fleurieu Peninsula", "Mornington Peninsula")) +
  scale_fill_brewer(palette = "Dark2",
                    name = "Region", 
                    labels = c("Bellarine/Surf Coast", "Fleurieu Peninsula", "Mornington Peninsula")) +
  scale_x_discrete(labels = c("weekday", "weekend/holiday"))